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, EventA开发者_如何学Gorgs 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,
AndrewUse the DataGridView.CurrentCell Property like this:
int row = dgvHardware.CurrentCell.RowIndex;
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.
精彩评论