3

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.

Luminous
  • 1,771
  • 2
  • 24
  • 43
  • Where to begin: Set some breakpoint inside your `ToolStripItemExtCollectionEditor` class and inspect the values you get there. – Uwe Keim Sep 10 '14 at 15:05
  • What I've found so far is selecting the component initiates a call to the constructor of the collection editor and upon opening the collection CreateNewItemTypes() is called. Is there a way for me to debug my designer? I might be able to see who's calling the properties constructors if I was able to do that. – Luminous Sep 10 '14 at 15:43
  • Maybe you can start a 2nd instance of VS, and connect the debugger to it. I know that this works with Expression Blend. – Dirk Sep 10 '14 at 15:48
  • Unfortunately, I've hit the VB Express capability wall. DX I did however find this [link](http://www.ninjatrader.com/support/forum/showthread.php?t=15671). My works blocks the link in the forum post so I don't know if this workaround works or not. I do have SharpDevelop, and you can "attach to process" with it. I don't know how to debug another instance of it though. – Luminous Sep 10 '14 at 18:37

1 Answers1

0

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.

ToolStripMenuItemExt has a CheckListSheet which contains a reference to ToolStripMenuItemExt's DropDownItems (I passed in dropdownitems byref and not byval). It has one property that returns the CheckLists object in CheckListSheet.

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.

CheckListSheet has the CheckLists object. The dropdownitems I pass in byref are stored in an ObservableToolStripItemCollection which hopefully when I get to testing it allows me to update the collection of checklists easier since it inherits ObservableCollection(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 CollectionBase type that stores CheckList objects.

CheckList

Purpose: Stores the ToolStripItemCollection whose 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 ToolStripItem objects to be displayed and added to a CheckList.

Right now it demands I give it a Type or array of Types so it can establish itself what type of CollectionEditor it is. I haven't be able to show a drop down of types or a drop down of ToolStripItem objects. 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 CollectionBase which means at design time there's no way for it to reference the dropdownitems. :sigh:

Luminous
  • 1,771
  • 2
  • 24
  • 43