Click here to Skip to main content
15,889,571 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

MSIL
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).
Posted
Updated 13-Jul-11 7:22am
v6

1 solution

I casted sender as DataGridViewComboBoxEditingControl. I was unaware of this object, but it seems to have a row property that I needed.
 
Share this answer
 
Comments
[no name] 13-Jul-11 13:58pm    
Thanks, that's really helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900