Question : DataGridView  AutoResizeColumns() not working with

Hi Experts,

I have an application that uses the TabControl to provide different pages of information. One of these Tabs contains a DataGridView. When data is loaded into the DataGridview using the attached code, AutoResizeColumns() only works when the DataGridView's page is the one currently visible. If the data is loaded when the DataGridViews page is not the current page (visible tab) then when the tab is selected and the DataGridview is made viewable the data has loaded OK but the AutoResizeColumns() has not worked. Any ideas?
Code Snippet:
1:
2:
3:
4:
5:
6:
Private Sub SetDataGridViewLeagueData()
        
   DataGridViewLeagueData.DataSource = GlobalLeagueDataList
   DataGridViewLeagueData.AutoResizeColumns()
 
End Sub

Answer : DataGridView  AutoResizeColumns() not working with

This can be influenced by what, if any, other settings you have relating to column widths.  

At the moment it sounds as though DataGridViewLeagueData has its .AutoSizeColumnsMode set to None.  If you set it, for instance, to AllCells (you can do this at design time) then the sizing should be done when the .DataSource is set, whether or not the DataGridView is then visible.  And you shouldn't need the line

   DataGridViewLeagueData.AutoResizeColumns()

Implications of handling it that way, however, would be that column widths would automatically adjust as entries changed and the user would not be able to resize columns by dragging their edges.  If that wouldn't, overall, be a satisfactory solution there are other approaches.  If that's the case, please come back saying what "rules" you wish to apply with respect to column widths.

Roger
Random Solutions  
 
programming4us programming4us