Deselect Row on DataGrid LostFocus

Jul 17, 2009 at 6:44 PM
Edited Jul 17, 2009 at 6:53 PM

We use Single Select of rows only.   My users want to make sure that if they are not actively working withthe grid... and they work with other controls/ETC, that the visual "Item Selected Style" is removed.  The Grid will appears as it did before they tried editing.

I've created a little wrapper class   myDataGrid : Microsoft.Windows.Controls.DataGrid.     Can I accomplish the deselect behavior by overridding the OnLostFocus event and setting     base.SelectedIndex = -1;?

 

 protected override void OnLostFocus(RoutedEventArgs e)
        {
            base.OnLostFocus(e);
            base.SelectedIndex = -1;
        }

        protected override void OnLostFocus(RoutedEventArgs e)

        {

            base.OnLostFocus(e);

            base.SelectedIndex = -1;

        }

 

Is this the right event to override?  Also. setting the selectedIndex seems to have no impact.

 

Regards,

Tracy