Selection lost when changing value of IsCategorized

Grids for WPF Forum

Posted 2 months ago by Guillaume Guimond-Croteau
Version: 19.1.0687
Avatar

Hi,

I am currently trying to keep a memory of the last item selected when IsCategorized is enabled and disabled, because when changing between the two, everything collapse and the selection is lost. 

I tried hooking on categorizedListBox.SelectionChanged (if you look at the Getting started example) and when it is triggered, I do this:

private void CategorizedListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            if (!PropertyGrid.IsCategorized)
            {
                //We are leaving the categorized mode, so we save the selected item in the old variable.
                _oldCategorizedSelectedGridItem = SelectedGridItem;                               
            }                
            else
            {
                //We are leaving the sorted mode, so we save the selected item in the old variable.
                _oldSortedSelectedGridItem = SelectedGridItem;
            }
                
            CategorizedSelectionChanged = true;
        }

The thing is that when I try to set SelectedGridItem back with one of the old saved values, it is not working. It always select the first item of the grid, even If I set IsSelected to true. I am certain that I am not setting SelectedGridItem back after, so am I even allowed to set SelectedGridItem this way? What should I do to fix this?

Comments (1)

Posted 2 months ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

I'm not quite sure what SelectedGridItem is here, but I'm assuming it's an IDataModel instance.  Keep in mind that each time the property grid rebuilds itself, it's going to create new ICategoryModel and IPropertyModel instances (both inherit IDataModel).  That might be why the selection set doesn't work later on, since they are different objects than what you persisted.

If you look at our PropertyGridSettingFocus QuickStart, you can see some APIs for finding an IDataModel by name and focusing it.  You probalby want to use some of that kind of logic.


Actipro Software Support

The latest build of this product (v22.1.4) was released 25 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.