Ran into this issue on several occasions.
When finding SelectedItem or selected column on say right click menu or selecting combo box in a cell. The SelectedItem will be null or the previously selected row.
private void ComboBox_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {
// Correct
m_BeginEditString = ((ComboBox)sender).SelectedValue.ToString();
// Wrong. selected item is last selected row, example clicking directly on combobox will not select row, and be null.
m_BeginEditRow = (RowItem)MyDataGrid.SelectedItem;
}
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox SelectedItem="{Binding myItem, Mode=TwoWay,
NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
ItemsSource="{Binding Source={StaticResource enum}}"
SelectionChanged="ComboBox_Changed"
LostKeyboardFocus="ComboBox_LostKeyboardFocus"
GotKeyboardFocus="ComboBox_GotKeyboardFocus" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Solved by doing it a completely different way, thanks @Ramesh Muthiah for direction:
}