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

Developer technologies | VB
0 comments No comments
{count} votes

Answer accepted by question author
  1. Xingyu Zhao-MSFT 5,381 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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.