C # Datatable Column Width

I have a problem with Datatable in C #. I have Datatable columns. I want to manually set the size of the columns, how to do this?

this is the code:

 dt = new DataTable(); DataColumn culAvs = new DataColumn("Avskiping", typeof(string)); DataColumn culKota = new DataColumn("Kota", typeof(string)); dt.Columns.Add(culAvs); dt.Columns.Add(culKota); dataGrid1.DataSource = dt; 
+7
source share
2 answers

If you are talking about the maximum length of data in columns, you might be interested in the DataColumn.MaxLength property. But if you are talking about the width of the columns in the column, you should use the Width property of the DataGrid column: dataGrid1.Columns[ ... ].Width = ...

+8
source

The data table does not contain properties associated with the UI, it is a data container. You need to define the visual properties of the column in the data grid.

+2
source

All Articles