Hierarchical Data Grid View Combo Box

1/19/2018by
Hierarchical Data Grid View Combo Box

My code: DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell(); DataTable data = new DataTable(); data.Columns.Add(new DataColumn('Value', typeof(string))); data.Columns.Add(new DataColumn('Description', typeof(string))); data.Rows.Add('5', '6'); data.Rows.Add('51', '26'); data.Rows.Add('531', '63'); cell.DataSource = data; cell.ValueMember = 'Value'; cell.DisplayMember = 'Description'; cell.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox; dataGridView1.Rows[0].Cells[0] = cell; It displays combobox but can't select any value of it. You generally don't work with the individual cell types in the DataGridView. Instead you want to add a column of type DataGridViewComboBoxColumn. So instead of your provided code you want something like: var column = new DataGridViewComboBoxColumn(); DataTable data = new DataTable(); data.Columns.Add(new DataColumn('Value', typeof(string))); data.Columns.Add(new DataColumn('Description', typeof(string))); data.Rows.Add('5', '6'); data.Rows.Add('51', '26'); data.Rows.Add('531', '63'); column.DataSource = data; column.ValueMember = 'Value'; column.DisplayMember = 'Description'; dataGridView1.Columns.Add(column); For reference, the documentation on the DataGridViewCombobBoxCell is on MSDN. You can also find information on the DataGridView in general there. Another very good reference is the.

Since you want to assign a different DataSource you can choose to add it to the second DataGridViewComboBox column itself or to that specific cell, Since you would know the RowIndex and ColumnIndex you could very well set a different DataSource based on the first value selected (dataGridView1[0,0] as DataGridViewComboBoxCell).DataSource = list of states EDIT Since you need to select the first item you can add this which should work fine (studpromo_gv[14, semy] as DataGridViewComboBoxCell). Airbus Performance Engineer Program Manual. Value = (studpromo_gv[14, semy] as DataGridViewComboBoxCell).Items[0].

You generally don't work with the individual cell types in the DataGridView. Instead you want to add a column of type DataGridViewComboBoxColumn. DataGridView with hierarchical data binding. I just developed an application based on hierarchical data view. It just shows as a normal data grid view.

Hierarchical Data Grid View Combo Box
Comments are closed.