Fix Datagridview Column Width?

Hobbyist_programmer 621 Reputation points
2021-02-21T21:14:40.853+00:00

Hallo,

I have a datagridview bound to bindingsource and I am setting datagridview columns width on form load. It works on load but when i reset/rebind the bindingsource , datagridview columns width are reset. Is there a way to fix the width permanently?

thanks

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,668 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xingyu Zhao-MSFT 5,361 Reputation points
    2021-02-22T07:14:27.247+00:00

    Hi @Hobbyist_programmer ,
    Try setting the width of Datagridview in 'DataBindingComplete' event.

        Private Sub DataGridView1_DataBindingComplete(sender As Object, e As DataGridViewBindingCompleteEventArgs) Handles DataGridView1.DataBindingComplete  
            For Each col As DataGridViewColumn In DataGridView1.Columns  
                col.Width = ...   
            Next  
        End Sub  
    

    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful