Silverlight DataGrid automatic selection when setting ItemSource/DataContext, sorting,

datagridsilverlight-2.0

Is there a way to turn off the automatic selection of the first row in the built-in DataGrid in Silverlight?

We build a lot of functionality based off the user selecting a row in a data grid. The automatic firing of SelectionChanged when databinding or sorting is really causing us issues. We have tried to put some guards around the selection, but can't seem get all problems covered.

For example, if you have DataGrid in a tab of a TabControl that is not shown when loading the screen and the DataGrid has a binding to a property of the DataContext that is a list of objects. The grid is not databound until the tab is shown. Is there an event telling us that the grid is databinding? Shouldn't the default behavior of databinding be not to select a row?

Thanks
Mike

Best Answer

Have you tried setting a boolean field (ex. bool dataGridFirstLoad) which you set to false in your User Control's constructor.

Then on the SelectionChanged event of the DataGrid, check if dataGridFirstLoad is false. If false set to true and set the SelectedItem to null.

Hope this helps.

Related Topic