开发者

How do i change the column width of a DataGrid

开发者 https://www.devze.com 2023-01-15 18:09 出处:网络
i\'m creating a user control in C# .net compact framework 3.5. And i\'m using a DataGrid Control with a DataTable as the DataGrid\'s DataSource.

i'm creating a user control in C# .net compact framework 3.5. And i'm using a DataGrid Control with a DataTable as the DataGrid's DataSource. i need to make some of the grid columns wider.

for some reason i can't...

i ju开发者_Python百科st couldn't find the method or property that controls the column width...

any ideas?

thanks in advance...


You're looking for the AutoSizeMode and Width properties of the columns.


sample code below -

foreach(DataGridColumnStyle vColumnStyle in myGrid.TableStyles[0].GridColumnStyles )
{
    if (vColumnStyle.HeaderText.ToLower()=="mycolumn")    
    {                
        vColumnStyle.Width = 60;            
    }
}
0

精彩评论

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