I am trying to implement a very simple spreadsheet functionality based on a DataGrid.
The user clicks on a cell
The user types a value and presses return
The current row is scanned and any cell formula that depends on the clicked cell is updated.
This seems to be the best event handler for my requirements:
private void my_dataGrid_CurrentCellChanged(object sender, EventArgs e)
Question: How do I detect the row index of the current row?
Try this (assuming the name of your grid is "my_dataGrid"):
var currentRowIndex = my_dataGrid.Items.IndexOf(my_dataGrid.CurrentItem);
Normally, you'd be able to use my_dataGrid.SelectedIndex
, but it seems that with the CurrentCellChanged
event, the value of SelectedIndex always displays the previously selected index. This particular event seems to fire before the value of SelectedIndex actually changes.