Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a gridview of which I would like the columns to be set dynamically. The grid is bound from a datatable and autogeneratecolumns is true.

The code im attempting to use is this. . .but it doesnt seem to make any difference:

C#
int colWidth = Int16.Parse("150");
       if (colWidth > 0)
       {
           for (int r = 0; r < gvMadeToStock.Rows.Count; r++)
           {
               for (int i = 0; i < gvMadeToStock.Rows[r].Cells.Count; i++)
               {
                   gvMadeToStock.Rows[r].Cells[i].Width = colWidth;
               }
           }
       }

Any advice would be appreciated. . .
Posted

try change Column width not cell width or try to set AutoSizeMode and FillWeight of each Column
C#
MyColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
MyColumn.FillWeight = 1/ColumnsCount;
 
Share this answer
 
v2
Comments
Christopher Trevor 21-May-12 4:59am    
Thanks for your reply. I should have specified, im working in asp.net so I dont have access to datagridview.
NewPast 21-May-12 5:04am    
try change Column width not cell width

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900