Skip to main content Skip to footer

How to expand/collapse specific categories in code for C1PropertyGrid for WPF

Background:

Arrow buttons for expansion/collapse are actually C1ExpanderButton that are part of C1Expander element present in each category. C1Expander has property IsExpanded that defines whether a category is expanded or collapsed.

So, access these C1Expander through C1PropertyGrid’s CategoryContainers and set the IsExpanded property for the specific category

Steps to Complete:

private void SetGroupState(C1PropertyGrid propGrd, string grpName, GroupState grpState)
{
     foreach(KeyValuePair<string, C1Expander> kvp in propGrd.CategoryContainers.Where(x=>x.Key== grpName))
     {
          C1Expander expander = kvp.Value;
          if(expander != null)
          {
               if(grpState == GroupState.Expanded)
                   expander.IsExpanded = true;
               else
                   expander.IsExpanded = false;
          }
     }
}
public enum GroupState
{
     Expanded = 0,
     Collapsed
}

Ruchir Agarwal