Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6128619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:38:50+00:00 2026-05-23T16:38:50+00:00

I have been struggling with this for a while now. I have a Master

  • 0

I have been struggling with this for a while now. I have a Master / Details layout in my application, and am faced, like many others, with the problem of the DataGrid loosing its selection when disabling it. Essencialy, after selecting an element from the list to populate a series of fields, the user presses “Edit”, wich disables the DataGrid and enables all of the form’s fields. Pressing the “Save” button will revert these actions after saving the data… Pretty strait forward.

I am on Windows 7 developping with VS 2010 in the .Net Framework 4.

What I have tried:
1) Based on this post, I have tried to use the DataGrid in the June 2009 version of the WPF Toolkit, but I had the same reaction.
2) Based on this WPF CodePlex bug report, I have tried to create a custom control based on the DataGrid and to override the OnIsEnabledChanged call to remove the call to “UnselectAllCells”, but with no code example, I can’t even get it to fire once. I have tried:

public class FormMainDataGrid : DataGrid
{
    static FormMainDataGrid()
    {
        IsEnabledProperty.OverrideMetadata(typeof(FormMainDataGrid), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnIsEnabledChanged)));
    }

    public FormMainDataGrid() : base() { }

    private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        d.CoerceValue(CanUserAddRowsProperty);
        d.CoerceValue(CanUserDeleteRowsProperty);

        //this was added in new version !!!
        /*
        if (!(bool)(e.NewValue))
        {
            ((DataGrid)d).UnselectAllCells();
        }
        */

        // Many commands use IsEnabled to determine if they are enabled or not
        CommandManager.InvalidateRequerySuggested();
    }
}  

but this still unselects the currently selected row as soon as I disable the DataGrid. I have tried to interprete the last comments (in the Codeplex bug report) like this:

public class FormMainDataGrid : DataGrid
{
    static FormMainDataGrid()
    {

    }

    public static void OverrideStuff() 
    {
        IsEnabledProperty.OverrideMetadata(typeof(FormMainDataGrid), new FrameworkPropertyMetadata(new PropertyChangedCallback(OnIsEnabledChanged)));
    }

    public FormMainDataGrid() : base() { }

    private static void OnIsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        d.CoerceValue(CanUserAddRowsProperty);
        d.CoerceValue(CanUserDeleteRowsProperty);

        //this was added in new version !!!
        /*
        if (!(bool)(e.NewValue))
        {
            ((DataGrid)d).UnselectAllCells();
        }
        */

        // Many commands use IsEnabled to determine if they are enabled or not
        CommandManager.InvalidateRequerySuggested();
    }
}

public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        FormMainDataGrid.OverrideStuff();
        base.OnStartup(e);
    }
}  

but that does not even fire the modified version of the method.

First, am-I going the right way for this? Considering that the Deselection is caused by this method, can I completely replace the internal call to ‘OnIsEnabledChanged’ for my own method?
Is there another way I could be tackling this problem?
Or more specificly, how can i stop the call to the base version of this method since it is not an override, thus I cannot ‘not’ call the base.OnIsEnabledChanged?

Thanks alot!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:38:51+00:00Added an answer on May 23, 2026 at 4:38 pm

    The same problem with the Up-Down key still exists with IsHitTestVisible = false.

    So what I ended up doing is re-working the custom control like this:

        public class FormMainDataGrid : DataGrid
        {
            public FormMainDataGrid() : base() {
                this.IsEnabledChanged += new DependencyPropertyChangedEventHandler(DataGrid_IsEnabledChanged);
                this.SelectionChanged += new SelectionChangedEventHandler(DataGrid_SelectionChanged);
            }
    
            private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs args)
            {
                if (this.IsEnabled)
                {
                    _selectedValue = this.SelectedValue;
                }
            }
    
            private object _selectedValue;
    
            private void DataGrid_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs args)
            {
                this.Dispatcher.BeginInvoke((Action)(() =>
                {
                    this.SelectedValue = _selectedValue;
                }), null);
            }
        }
    

    This works pretty well… I just have to be carefull because changing the SelectedValue when the control is disable will then put it off track…

    So in conclusion, I believe that your solution is the most complete, but mine allows me to keep my form’s code as lean & mean as possible.

    Thanks for your help!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling with this problem for a while now, searching every possible solution.
I've been struggling for this for a while now. I'm trying to gear up
I've been struggling with this issue for a little while now. Found several posts
I've been struggling with this for a little while now.. I am using this
Good Morning All. I've been struggling with this issue for a while now, and
I have been struggling with this seeminly easy problem for 48 hours, and I
I have been struggling with this for a while and can't find the answer
I have been struggling with this for long. I read many resources but still
I have been struggling with this issue for about 10 hours straight. I really
I've been struggling with Logging in Wordpress for a while now with CURL (PHP).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.