Expanding the newest added item in a PropertyGrid

Grids for WPF Forum

Posted 1 year ago by Neil Larson
Avatar
      private void ThePropertyGrid_PropertyChildAdded(object sender, PropertyModelChildChangeEventArgs e)
      {
         PropertyGrid grid = sender as PropertyGrid;
         if (grid == null)
            return;

         for (int i = 0; i < grid.Items.Count; i++)
         {
            PropertyDescriptorPropertyModel m = grid.Items[i] as PropertyDescriptorPropertyModel;
            if(m != null)
            {
               if (Object.ReferenceEquals(m.Value, e.ChildValue))
               {
                  m.IsExpanded = true;
                  return;
               }
            }
         }
      }

 

I use this to expand the item just added by the user.  It would be a bit easier if e.ChildPropertyModel was not null, but this works too.

 

Neil

Comments (1)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Neil,

The problem is that right before we raise that event, we call a "refresh" on the parent's children collection.  We don't know the property model instance that gets generated as a result of that refresh. 

In general something like this might work better for your needs:

var propModel = parentPropertyModel.Children.FirstOrDefault(m => ((IPropertyModel)m).Value == childValue);
if (propModel != null)
    propModel.IsExpanded = true;


Actipro Software Support

The latest build of this product (v2018.1 build 0675) 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.