Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Datatable column width

Tags:

c#

.net

datatable

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;
like image 927
Roi84 Avatar asked Sep 20 '11 09:09

Roi84


2 Answers

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 = ...

like image 153
Dmitry Avatar answered Sep 21 '22 14:09

Dmitry


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.

like image 44
vc 74 Avatar answered Sep 17 '22 14:09

vc 74