Hey guys,

I have a datagridview called DataGridView1 which has four column each are combobox's, I need to be able to change the items in one of the comboboxes based on the previous one. For example

I have a column named FieldName which has the following values:

2. ID

if the user selects products i want to be able to change a combobox called Value to "HomeProject","Work Stuff"

Would anyone have any ideas on how to do this.

If searched around and could not find anything...please help :S

Thanks in advance

Assuming you've defined each column of type DataGridViewComboBoxColumn, you'll want to add a handlers for the events: EditingControlShowing and CellBeginEdit. We use CellBeginEdit to identify the active cell and EditingControlShowing to obtain the edit control. The args DataGridViewCellCancelEventArgs and DataGridViewEditingControlShowingEventArgs provide us with the data access we need to set the dropdown list.


private void dgv_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
m_iActiveCellCol = e.ColumnIndex;

private void dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
ComboBox cbx;
if(m_iActiveCellCol ==2)
cbx = (ComboBox)e.Control;
cbx.DataSource = m_oCol2DataSource;
cbx.DisplayMember = oCol2DataSource.DisplayMember;

Edited 3 Years Ago by happygeek: fixed formatting

A much easier way in fact is to simple cast the particular column that you want to modify as the code below demonstrates:

DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)dgv.Columns["Value"];
col.Items.Add("Work Stuff");

This article has been dead for over six months. Start a new discussion instead.