DataGrid selection changes when IsEnabled changes

Mar 9, 2010 at 9:09 PM

I get different behavior for the DataGrid when I use Windows 7 vs. Vista. In Vista, if I select a row in the datagrid and then disable it, the row remains selected. In 7, the row becomes deselected and the SelectedChanged event of the datagrid fires. Is it possible to set the DataGrid so that it does not clear the selection when being disabled?

Here is a simplified example in C#:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace WpfApplication2
    class TestClass
        private String mProp1 = null;
        private String mProp2 = null;

        public String Prop1
            get { return mProp1; }
            set { mProp1 = value; }

        public String Prop2
            get { return mProp2; }
            set { mProp2 = value; }

        public TestClass(String prop1, String prop2)
            Prop1 = prop1;
            Prop2 = prop2;

    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
        public Window1()

            ObservableCollection<TestClass> list = new ObservableCollection<TestClass>();
            list.Add(new TestClass("1", "One"));
            list.Add(new TestClass("2", "Two"));
            list.Add(new TestClass("3", "Three"));

            mDataGrid.ItemsSource = list;

        private void Button_Click(object sender, RoutedEventArgs e)
            mDataGrid.IsEnabled = !mDataGrid.IsEnabled;

And here is the xaml:


<Window x:Class="WpfApplication2.Window1"
    Title="Window1" Height="300" Width="300">
        <wpftk:DataGrid Name="mDataGrid"></wpftk:DataGrid>
        <Button Name="btnToggle" Click="Button_Click">Toggle Datagrid Enabled</Button>




Mar 11, 2010 at 1:33 AM

I have same problem.

I found it in Issue Tracker.

Vote it.