DataGrid CurrentItem != SelectedItem after reentry with tab-button DataGrid CurrentItem != SelectedItem after reentry with tab-button wpf wpf

DataGrid CurrentItem != SelectedItem after reentry with tab-button


Usually I bind the SelectedItem to a property in the DataContext, and set IsSynchronizedWithCurrentItem to false.

<DataGrid ItemsSource="{Binding SomeCollection}"          SelectedItem="{Binding SelectedItem}" />

Setting IsSyncrhonizedWithCurrentItem to true will make it so the SelectedItem of the Control is synchronized with the CurrentItem property of a collection, however I've had issues with this since I don't always understand how CurrentItem gets and maintains its value.


Two ways to resolve this:

  1. Log a bug report with Microsoft Support, stating that IsSynchronizedWithCurrentItem doesn't always work when you use TAB.

  2. Bind the SelectedItem to the current cell's row, which is stored in the CurrentCell's Item property:

    <DataGrid SelectedItem="{Binding RelativeSource={RelativeSource Self}, Path=CurrentCell.Item, Mode=OneWay}" />