Im having a problem with Datatable in C#. I have a Datatable
with to columns. I want to manually set the size of the columns, how do I 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;
If you're talking about maximal length of data in columns, you might be interested in DataColumn.MaxLength
property. But if you're talking about visual width of columns you should use Width
property of a DataGrid's column: dataGrid1.Columns[ ... ].Width = ...
The data table does not contain UI related properties, it's a data container. You need to define the column visual properties on the data grid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With