Hello WaseemAmin,
Unfortunately the DataGridViewComboBoxColumn doesn't expose a SelectedIndexChanged Event. In order to catch an index change of a ComboBoxColumn, you 'll first need to cast the cell to a DataGridViewComboBoxEditingControl and Add an EventHandler to that control. This you will have to do in the EditingControlShowing Event of the DataGridView .
suppose i have a datagridview named as dataGridViewSales .and in the datagridview i have one combobox . Now i want to change the datagrid view second column value according to combobox selected value.
private void dataGridViewSales_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged += new EventHandler(selectionchange);
}
}
and then define selectionchange method
void selectionchange(object sender, EventArgs e)
{
try
{
ComboBox cb = (ComboBox)sender;
if (cb.Text == "yes")
{
dataGridViewSales.CurrentRow.Cells[1].Value= "Hello";
}
else if (cb.Text == "no")
{
dataGridViewSales.CurrentRow.Cells[1].Value = string.Empty;
}
}
catch { }
}
thanks