Idea

Expanding the newest added item in a PropertyGrid

Posted 9 months ago by Avatar Neil Larson
      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 9 months ago by Actipro Software Support - Cleveland, OH, USA

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
Information The latest build of this product (2018.1 build 0672) was released 2 months ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.

Set the number of votes that you'd like to apply to this idea. You have 10 of 10 votes available.

0 supporters, with an average vote of 0.00.