Passing an Object to the Collection Editor
I am trying to create a checklist for ToolStripMenuItem
that automatically handles the check and uncheck of an item, and then I provide an event to the programmer to allow them to handle what comes next. If something like this already exists, I would LOVE to know where it is. I created a collection editor for my custom ToolStripMenuItem
one and I can add checklists to this collection of checklists. My problem is that you create a collection editor like this:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Editor(typeof(ToolStripItemExtCollectionEditor), typeof(UITypeEditor))]
I need to pass this one ToolStripMenuItem
DropDownitems
to this collection editor, so when you add a new checklist and click on the items property of the checklist, you can add / remove any of the known ToolStripMenuItems to / from the checklist. Passing the link will not work as it all happens inside an attribute and I have no idea where to start if the response is reflection.
source to share
This answer is specific to VB.NET. I'm planning to turn this into C # for a DLL, but for now it's in vb.net because that's where I started this idea and in the language the project is in.
Here's what I have so far:
ToolStripMenuItemExt
Purpose: My custom ToolStripMenuItem
.
ToolStripMenuItemExt
has CheckListSheet
one that contains a link to ToolStripMenuItemExt
DropDownItems (I passed byref to dropdownitems, not byval). It has one property which returns an object CheckLists
in CheckListSheet
.
CheckListSheet
Purpose: Maintains a reference to the collection that I am observing through the observable type of the collection and the collection object that I am returning to ToolStripMenuItemExt
.
CheckListSheet
has an object CheckLists
. The dropdowns I pass to byref are stored in ObservableToolStripItemCollection
, which hopefully when I get to testing it allows me to update the collection of checklists more easily as it inherits ObservableCollection(of ToolStripItemCollection)
. This class also has a generic function that returns an observable collection that has a private scope identifier.
CHECKLISTS
Purpose: the type CollectionBase
in which the objects are stored CheckList
.
CheckList
Purpose: Stores ToolStripItemCollection
whose objects act as a single item checklist (only one item is checked at a time).
This has some properties for the designer and collection for the checklist. Eventually, I'll add logic to check and automatically uncheck and raise an event for it.
MenuItemCheckListCollectionEditor
Purpose: Allows to display known and created instances of ToolStripItem
objects that will be displayed and added to CheckList
.
At the moment I need to specify a type or an array of types so that it can determine what type CollectionEditor
it is. I cannot show the descent of types or dropdowns ToolStripItem
. Any class that has a ToolStrip in its name inherits ToolStripItem, so I use that object type.
If ANYONE has any advice on my current answer, or can predict any predictable pitfalls, please share. I don't care if you are talking in C # or vb.net. Maybe I just need to stop and turn this into C # code. It may not be possible. However, I am making progress. What would be extremely useful is to figure out how the MenuStrip collection editor can populate the ToolStripItems dropdown
[Update]
The collection editor requires that you provide a type to display. This type must inherit CollectionBase
, which means there is no way at design time to reference dropdownitems .: Sigh:
source to share