Stop Datagrid selecting first row by default

Check if you have set IsSynchronizedWithCurrentItem="True" and you require it to be set alike?

<DataGrid IsSynchronizedWithCurrentItem="True" ... 
            
            

With set this property to true, the selection of the first item is the default-behaviour.


Chances are that your DataGrid is bound to a collection like PagedCollectionView that has a CurrentItem property. This property is auto-synchronized with the selected row, in both directions. The solution would be to set the CurrentItem to null. You can do it like this:

PagedCollectionView pcv = new PagedCollectionView(collection);
pcv.MoveCurrentTo(null);
dataGrid.ItemsSource = pcv;

This is especially helpful in Silverlight, which has no DataGrid.IsSynchronizedWithCurrentItem property...

Tags:

C#

Wpf

Datagrid