I'm using PropertyGrid to edit an object containing a collection. Collection is edited using the CollectionEditor. I have to make sure elements in collection are unique.
How can I add validation to CollectionEditor:
- By either overloading CollectionEditor's OnFormClosing
- Or adding validation for creating/editing items?
You can create your own collection editor, and hook into events on the default editor's controls. You can use these events to, say, disable the OK button. Something like:
You will also need to add an Editor attribute to you collection:
NOTE: I found that the value of items in removeButton_Click was not correct - so some tweaking may need to take place.