This seems to be a straight forward thing, but Microsoft only knows why this simple feature is not supported in DataGridView.
If you have a ComboBoxColumn in your DataGridView and you want to know what is the selected index of the combo box, then you need to do this:
1. Handle the EditingControlShowing event of DataGridView. In this event handler, check if the current column is of our interest. Then we create a temporary ComboBox object and get the selected index:
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 0)
{
// Check box column
ComboBox comboBox = e.Control as ComboBox;
comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
}
}
void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = ((ComboBox)sender).SelectedIndex;
MessageBox.Show("Selected Index = " + selectedIndex);
}
A rather round-about solution where a simple one would have sufficed.

February 19, 2008 at 9:28 pm
You can do it using:
((DataGridView)sender).CurrentCell.RowIndex
May 23, 2008 at 11:02 am
Great help
October 22, 2008 at 5:03 pm
Excellent Job!!! . Keep It Up . God Bless u with more nurturing capabilities so that programmers like us keeps on geetting tips from u…………….. Thank u…………………………
November 19, 2008 at 2:26 pm
Nice piece of code! Thanks
January 27, 2009 at 3:08 pm
Thanks man,
It’s exactly what i want.
May 13, 2009 at 5:14 pm
thanks man..
really helped..
May 26, 2009 at 2:45 pm
Its working thanks
May 29, 2009 at 4:09 pm
Thanks a lot , I was struggling for 1 day for this
October 5, 2009 at 3:29 pm
Thanks dude…. This code is helped me lot…
October 6, 2009 at 11:09 am
thank u very much dear …..i got lot of help from this effective code
November 19, 2009 at 2:17 pm
Hi,
Thanks for the “life saving” work around.
I am using it further to enable a button which is outside of grid depending
on the value selected in ComboBoxCell.
The code below works well if I change the values of only one ComboBox, but
when I try to change values in multiple it fails.
e.g. to disable the Save button I have to make all ComboBox values = “Select”
which is default value, even after that IsItemSelected method returns “true”
After inserting a break point at
>> if (cell.Value.ToString() != “Select”)
I still get the last value in Cell which is other than “Select”
void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = ((ComboBox)sender).SelectedIndex;
//MessageBox.Show(“Selected Index = ” + selectedIndex);
if (selectedIndex > 0)
{
btnSave.Enabled = true;
}
else
{
// check for all rows
btnSave.Enabled = (IsItemSelected() == true ? true : false);
}
}
private bool IsItemSelected()
{
bool isItemSelected = false;
foreach (DataGridViewRow dgvRows in dgvPending.Rows)
{
DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dgvRows.Cells[0];
if (cell != null)
{
if (cell.Value.ToString() != “Select”)
{
isItemSelected = true;
break;
}
}
}
return isItemSelected;
}
Please guide
Thanks in advance