PropertyGrid expanded/collapsed categories

Grids for WPF Forum

Posted 11 months 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 11 months 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 11 months ago]

Posted 11 months 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 (v21.1.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.