Quantcast
Viewing all articles
Browse latest Browse all 18858

WPF DataGrid: How to determine the index of the row in which a ComboBox selection changed?

I have been using this code, in order to determine the current row being edited interactively:

private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    MyModel myModel = (MyModel) dataGrid.CurrentItem;
    int rowIndex = dataGrid.Items.IndexOf(myModel);
    [...]
}

The limitation of this approach is that the event handler is also executed when the ComboBox selection changesprogrammatically. In that case, CurrentItem is null and thus I don't know the row index.

In fact, I do not really need the row index per se, I could use the Model (CurrentItem) as well.

TIA


Viewing all articles
Browse latest Browse all 18858

Trending Articles