How to change the width of a DataGrid column

I am creating a user control in C # .net compact framework 3.5. And I use DataGrid Control with a DataTable as a DataGrid DataSource. I need to make some of the grid columns wider.

for some reason I can’t ...

I just couldn't find a method or property that controls the column width ...

any ideas?

thanks in advance...

+3
source share
2 answers

You are looking for column properties AutoSizeModeand Width.

+1
source

sample code below -

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

Source: https://habr.com/ru/post/1764499/


All Articles