Hi all,
I have a custom UI control with a collection property that I can edit with a
CollectionEditor at design-time.
To achieve this I've used the Editor attribute (from System.ComponentModel)
on the collection property and created a class that derives from
CollectionEditor and overrides some methods. To keep it simple the type of
items the collection contains are objects with a single string property
called Name.
I'm looking for a way to validate new added items in CollectionEditor to
make sure that they all have a unique Name in the collection.
So far I've tried overriding CreateInstance() and SetItems() methods, but
haven't been able to enforce unique names.
Any ideas?
Thanks in advance.
Dave Sexton - 21 Jun 2006 23:37 GMT
Hi Sergiy,
Override the CreateControlsInstance method and return a custom
Control.ControlCollection-derived Type. You can override the Add and
AddRange method to check if the name is unique before allowing the Control
to be added to the collection. You can throw and error if the name is not
unique. The error thrown by your custom Control.ControlCollection-derived
Type will be caught by VS.NET and displayed to the user as a standard dialog
error.
HTH
> Hi all,
> I have a custom UI control with a collection property that I can edit with
[quoted text clipped - 15 lines]
>
> Thanks in advance.