fix a columns width when a list is bound to a datagridview
Posted
by Andy
on Stack Overflow
See other posts from Stack Overflow
or by Andy
Published on 2010-03-17T20:47:16Z
Indexed on
2010/03/17
20:51 UTC
Read the original article
Hit count: 266
I have a list that I have bound to a datagridview. I want the first column to be a fixed size. The data is bound to the dataGridView and I can't seem to find a way to access an individual colums properties. if I try myDatagridview.colums[0] I get an index out of bounds, since it says the columns count is 0.
private DataGridView setUpDataGrid(List<NVRlineVal> _NVRData)
{
//setup dataGridView
DataGridView NVRDataGridView = new System.Windows.Forms.DataGridView();
NVRDataGridView.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
NVRDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
NVRDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
NVRDataGridView.Location = new System.Drawing.Point(3, 3);
NVRDataGridView.Name = "NVRDataGridView" + nvrIndex;
NVRDataGridView.RowHeadersWidthSizeMode =
System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
NVRDataGridView.Size = new System.Drawing.Size(380, 401);
NVRDataGridView.TabIndex = 0;
NVRDataGridView.DataSource = _NVRData;
var test = NVRDataGridView.Columns;
NVRDataGridView.DataMember = "devState";
DataGridViewAutoSizeColumnMode.None;
}
Any ideas on how to have a fixed column width for only one of these columns, the rest will autosize?
© Stack Overflow or respective owner