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.Da开发者_Python百科taSource = 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.
精彩评论