문제

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?

도움이 되었습니까?

해결책

Add to your ComboBoxColumn a column name of datagridview datasource:

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

cmbCol.DataPropertyName = "ColumnNameOfMainDataTable";
this.dgGridVw.Columns.Add(cmbCol);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top