Fuginator
Fuginator

Reputation: 229

DataGridView ComboBox EditingControlShowing events

I have a basic WinForms app with d DataGridView (named dgvHardware) control on it, bound to this control is this code:

    private void dgvHardware_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (e.Control is ComboBox)
        {
            ((ComboBox)e.Control).SelectionChangeCommitted -= new EventHandler(cboDgvHardware_SelectionChanged);
            ((ComboBox)e.Control).SelectionChangeCommitted += new EventHandler(cboDgvHardware_SelectionChanged);
        }
    }

    private void cboDgvHardware_SelectionChanged(object sender, EventArgs e)
    {
        // string result is the selected text of the combo box
        // int row is the row index that the selected combo box lives
        string result = ((ComboBox)sender).SelectedItem.ToString();
        // int row = ????
    }

Long story short, I need to be able to determine the row that the events are being fired on, in order to change other cells in the row based on the ComboBox selection. The result in the second function returns correct values, for what it's worth.

Let me know if this is unclear or if you need any additonal information.

Thanks,
Andrew

Upvotes: 3

Views: 11809

Answers (2)

V4Vendetta
V4Vendetta

Reputation: 38210

You would be interested in the dgvHardware.CurrentRow which will give you acess to the entire row and you could navigate to different columns using dgvHardware.CurrentRow.Cells[index or columnName] and change the other cell values.

Upvotes: 1

Jay Riggs
Jay Riggs

Reputation: 53593

Use the DataGridView.CurrentCell Property like this:

int row = dgvHardware.CurrentCell.RowIndex;

Upvotes: 6

Related Questions