开发者

When i change the datasource on My datagrid the columns dont autofill unless i order a column

开发者 https://www.devze.com 2023-01-18 00:22 出处:网络
I have a DataGrid on a Win Form that display perfectly when I initially set the datasource. The AutoSizeColumnsMode is \"DisplayCells\". When I change the datasource during runtime the rows do not aut

I have a DataGrid on a Win Form that display perfectly when I initially set the datasource. The AutoSizeColumnsMode is "DisplayCells". When I change the datasource during runtime the rows do not autosize u开发者_高级运维nless I re-order a column. Does anyone know how to fix this? Also note that the DataGrid is on a different Tab than the button that calls the update.

The only code that I ever use to populate the grid is:

dgUnPrinted.DataSource = TableName;
dgUnPrinted.Refresh();


try http://www.codeproject.com/KB/miscctrl/AutoResizeDataGrid.aspx or http://www.hanselman.com/blog/HowDoIAutomaticallySizeAutosizeColumnsInAWinFormsDataGrid.aspx

or use DataGridView then you can play with gdv.Columns[0].AutoSizeMode property.


Did you try the AutoResizeColumns method?

http://msdn.microsoft.com/en-us/library/ms158595%28v=VS.90%29.aspx


After some thinking I decided to sort a column through code. This filled out all the cells. I am not sure why this is needed or why it works when everything else does not work but at least i have a fix.

dgUnPrinted.Sort(dgUnPrinted.Columns[0], ListSortDirection.Ascending);          
0

精彩评论

暂无评论...
验证码 换一张
取 消