Question

I am working on Windows Application. I have a DataGridView in which I am displaying some data from table. With the addition I have created 1 ComboBoxColumn in DataGridView like this:

DataGridViewComboBoxColumn cmbCol = new DataGridViewComboBoxColumn();
cmbCol.Name = "cmbData";
cmbCol.HeaderText = "Data";
cmbCol.ToolTipText = "Data";
DataTable dt = GetList();
cmbCol.ValueMember = dt.Columns[1].ColumnName;
cmbCol.DisplayMember = dt.Columns[1].ColumnName;
cmbCol.DataSource = dt;
this.dgGridVw.Columns.Add(cmbCol);

In this way, when I tried to run my application, I am getting values in the ComboBoxColumn. But Now I want that when run the application, after loading form, ComboBoxColumn should display specific value which is there in Database table.

Can someone help please?

Was it helpful?

Solution

Add to your ComboBoxColumn a column name of datagridview datasource:

DataGridViewComboBoxColumn cmbCol = new DataGridViewComboBoxColumn();
//...your code...

cmbCol.DataPropertyName = "ColumnNameOfMainDataTable";
this.dgGridVw.Columns.Add(cmbCol);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top