Greetings fellow QA answerers, time for a question from one of your own.
I will explain what I'm doing first. I have a DataGridView control that is legacy, has to remain this type. It contains 3 columns, 2 of which is a ComboBox. When the first column changes to a type, the datasource for the second column should be populated with 2 values. When it is anything except this type, the dataset should be wiped so it cannot be accessed (kind of a way to disable the combobox).
I get the event for when the selected index of the first column's combo box is changed with this:
private void dbPlatform_EditingControlShowing(object _sender,
DataGridViewEditingControlShowingEventArgs e)
{
DataGridView dgv = _sender as DataGridView
ComboBox cb = e.Control as ComboBox
if (cb != null)
{
int row = dgv.CurrentCell.RowIndex
int column = dgv.CurrentCell.ColumnIndex
if (column == 0)
{
cb.SelectedIndexChanged -= (sender, args) => cb_SelectedIndexChanged(sender, row, column)
cb.SelectedIndexChanged += (sender, args) => cb_SelectedIndexChanged(sender, row, column)
}
}
}
I really only need this to fire for the row that contains the combobox thats index is being changed. The problem is, lets say I have row 4 column 1 change, this gets called for each row.
ADDED:
I should clarify the big issue. I can't find a way to get the row number or row index of the combobox cell that fires this event. I can cast the _sender as a ComboBox, or a DataGridView, but not a DataGridViewComboBoxCell which would contain the data I need (row index).