I'm trying to build a check list for a ToolStripMenuItem that automatically handles the checking and unchecking of an item and then I provide an event to the programmer allowing them to handle what happens next. If something like this already exists, I would LOVE to know where it is. I've created the collection editor for my custom ToolStripMenuItem and I can add check lists to this collection of checklists. My problem is you create the collection editor like this:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor(typeof(ToolStripItemExtCollectionEditor), typeof(UITypeEditor))]
I need to be able to pass this ToolStripMenuItem's 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 one of the known ToolStripMenuItems to/from the checklist. Passing a reference won't work since all of this is happening inside an attribute and I wouldn't know where to begin if the answer is reflection.
This answer applies to VB.NET. I plan on turning this into C# for a DLL, but for now it's in vb.net because that's where I started this idea from and the language the project is in.
Here's what I have so far:
ToolStripMenuItemExt
Purpose: My custom
ToolStripMenuItem.ToolStripMenuItemExthas aCheckListSheetwhich contains a reference toToolStripMenuItemExt's DropDownItems (I passed in dropdownitems byref and not byval). It has one property that returns theCheckListsobject inCheckListSheet.CheckListSheet
Purpose: Maintains a reference to the collection I'm observing through an observable collection type and an object of the collection I return in
ToolStripMenuItemExt.CheckListSheethas theCheckListsobject. The dropdownitems I pass in byref are stored in anObservableToolStripItemCollectionwhich hopefully when I get to testing it allows me to update the collection of checklists easier since it inheritsObservableCollection(of ToolStripItemCollection). This class also has a shared function that returns the observable collection which has a scope identifier of private shared.CheckLists
Purpose: The
CollectionBasetype that storesCheckListobjects.CheckList
Purpose: Stores the
ToolStripItemCollectionwhose objects act as a single item checked checklist (only one item is checked at a time).This has some properties for the designer and the collection for the check list. Eventually I'll add in the logic to check and automatically uncheck and raise an event for it.
MenuItemCheckListCollectionEditor
Purpose: Allows a collection of known and instantiated
ToolStripItemobjects to be displayed and added to aCheckList.Right now it demands I give it a Type or array of Types so it can establish itself what type of
CollectionEditorit is. I haven't be able to show a drop down of types or a drop down ofToolStripItemobjects. Any class having ToolStrip in their name inherits ToolStripItem which is why I use this type of object.If ANYONE has any advice on my current answer or can forecast any foreseeable pitfalls please share. I don't care if you talk in c# or vb.net. Maybe I just need to stop and turn this into c# code. Maybe this is impossible. I am making progress though. What would be extremely helpful is figuring out how MenuStrip's collection editor is able to populate a dropdown of ToolStripItems
[Update]
A collection Editor requires you to provide a type for it to display. This type has to inherit
CollectionBasewhich means at design time there's no way for it to reference the dropdownitems. :sigh: