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
Use the DataGridView.CurrentCell Property like this:
int row = dgvHardware.CurrentCell.RowIndex;