Q:

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 changes programmatically. In that case, CurrentItem is null and thus I don't know the row index.
TIA
Note: I do not really need the row index per se, I could use the Model (CurrentItem) as well.
Edited after I solved the problem: Notice how the code above ignores the arguments (which tend to contain really important stuff!!)

A:

This is what I was looking for...
private void ComboBoxRight_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    ComboBox comboBox    = (ComboBox) sender;
    DataGridRow row      = (DataGridRow) dataGrid.ContainerFromElement(comboBox);
    int rowIndex         = row.GetIndex();
    MyModel gridModel    = (MyModel) dataGrid.Items[rowIndex];
}

-Travis

