PropertyGrid expanded/collapsed categories

Grids for WPF Forum

Posted 4 years ago by Procam
Version: 20.1.0


is there a way how to preserve the collapsed/exttended categories in PropertyGrid?

For example:

I have a class MyClass with properties A, B, C and D:

- Properties A and B have attribute [Category("Info")]

- Property C has attribute [Category("General")]

- Property D has attribute [Category("Misc")]

Is there a way how to display at first loading (until user manually changes it) the category "Info" as expanded?

What I need is to have all categories collapsed, and only the "Info" to be expanded.


Comments (2)

Posted 4 years ago by Procam

Just, the answer to my question :)

private void OnCustomPropertyGridRootItemChanged(object sender, System.Windows.RoutedEventArgs e)
    if (!(e.OriginalSource is CustomPropertyGrid)) return;
    System.Collections.ICollection items = ((CustomPropertyGrid)e.OriginalSource).Items;
    object[] array = new object[items.Count];
    items.CopyTo(array, 0);
    for (int i = 0; i < array.Length; i++)
        if (!(array[i] is ICategoryModel cat)) continue;
        cat.IsExpanded = cat.Name == "Info";

[Modified 4 years ago]

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA


Another way would be to make a class that inherits TypeDescriptorFactory and override the GetDataModels method to call its base method, examine the results, and expand ICategoryModels as appropriate.  

Actipro Software Support

The latest build of this product (v24.1.2) was released 27 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.