Home › Forums › WPF controls › Xceed Toolkit Plus for WPF › Responding to CollectionChanged event in PropertyGrid
-
AuthorPosts
-
#43966 |
Hi,
I’ve got a PropertyGrid in a project with a Property that is a collection. Now I know about the CollectionEditor, but I don’t like it. I like editing my objects right in the list, so I’ve got this property:
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Xceed.Wpf.Toolkit.PropertyGrid.Attributes; using Xceed.Wpf.Toolkit.PropertyGrid.Editors; namespace QJExternalTool { [ExpandableObject] public class IntentionList : ObservableCollection<OrderIntention>, ICustomTypeDescriptor { // Implementation of ICustomTypeDescriptor: public String GetClassName() { return TypeDescriptor.GetClassName(this, true); } public AttributeCollection GetAttributes() { return TypeDescriptor.GetAttributes(this, true); } public String GetComponentName() { return TypeDescriptor.GetComponentName(this, true); } public TypeConverter GetConverter() { return TypeDescriptor.GetConverter(this, true); } public EventDescriptor GetDefaultEvent() { return TypeDescriptor.GetDefaultEvent(this, true); } public PropertyDescriptor GetDefaultProperty() { return TypeDescriptor.GetDefaultProperty(this, true); } public object GetEditor(Type editorBaseType) { return TypeDescriptor.GetEditor(this, editorBaseType, true); } public EventDescriptorCollection GetEvents(Attribute[] attributes) { return TypeDescriptor.GetEvents(this, attributes, true); } public EventDescriptorCollection GetEvents() { return TypeDescriptor.GetEvents(this, true); } public object GetPropertyOwner(PropertyDescriptor pd) { return this; } public PropertyDescriptorCollection GetProperties(Attribute[] attributes) { return GetProperties(); } public PropertyDescriptorCollection GetProperties() { // Create a new collection object PropertyDescriptorCollection PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null); // Iterate the list of employees for (int i = 0; i < this.Count; i++) { OrderIntentionItemDescriptor pd = new OrderIntentionItemDescriptor(this, i); pds.Add(pd); } return pds; } public override string ToString() { return base.Count.ToString(); } } }
My problem is the PropertyGrid does not update the list when items are added or removed to the collection. How would I go about notifying it that it needs to re-list the properties?
Hi,
Could you send me a simple stand alone sample project which reproduces the issue so that I could have a closer look. You may send it to: support@xceed.com
Hi,
Try adding a check to collection changed to be notified on each addition or removal:
DummySpread.Intentions.CollectionChanged += Intentions_CollectionChanged.
In the callback, reset the SelectedObject. If you want to keep the PropertyItem expanded, you can expand it :
private void Intentions_CollectionChanged( object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e )
{
_speadPropertyGrid.SelectedObject = null;
_speadPropertyGrid.SelectedObject = DummySpread;
_speadPropertyGrid.ExpandProperty( “Intentions” );
} -
AuthorPosts
- You must be logged in to reply to this topic.