views:

25

answers:

3

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 unless 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();
A: 

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.

Hasu
Thats some really old information. .NET 2.0 has built in methods which i am using to accomplish this.
Confused SQL User
A: 

Did you try the AutoResizeColumns method?

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

Coding Gorilla
Yes, i even tried resetting it.
Confused SQL User
A: 

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

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

Confused SQL User