fix a columns width when a list is bound to a datagridview
- by Andy
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?