Adding a custom control to a toolstrip

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
After getting past the first hurdle of toolstrip items(combobox hell!!!!) I have decided to create a user control, consisting of two date pickers and a button to allow me to gather date between parameters to bung into stored proc. I have got the control and referenced it in my application, but am wondering how to show this in my menu structure. Cannot use the earlier solution of casting a toolstripcombobox to my custom so how would I embed further down menu structure. Again I can add at top level but not what I am after..

Ta for any assistance peeps.
 
Thanks for the reply John. I'm ok with adding a control to a toolstrip by creating a control, casting and adding with the ts.items.add statement but my problem is how to add my custom control at a specific point in my menu structure, i.e dropdownbutton then a couple of menuitems. Across from one of these menuitems I wish to add my control. Not sure how to insert at this point.???

Cheers.
 
Use the Add or Insert method of the main ToolStripMenuItem.DropDownItems collection:
VB.NET:
Dim uc As New yourUserControl
Dim host As New ToolStripControlHost(uc)
ViewToolStripMenuItem.DropDownItems.Add(host)
'or
ViewToolStripMenuItem.DropDownItems.Insert(index, host)
 
Cheers for your help John. Do you know how I can add my custom control to the right of an existin dropdown menuitem though?

I have my menu structure set up at design time in the ide then at runtime need to add my control to the right of a menuitem, structure is summot like:

Clients:
---->Client Searches:
------->"By Area"------>Combo*Combos I have ok*
------->"By Worker"---->Combo
------->"Reviewed between two dates" ---> <My custom object here>
------->"Some other searches"

Really struggling with obtaining an index for this position to perform insert?????
 
Each menu item that has got child menu items is the main menu for its branch. So your 'Client searches' has got a name you can replace where I used 'ViewToolStripMenuItem'. If the three other menu items you have listed in that branch already exists you use the Insert method with index 2 (zero-based)
 
You've already given me the answer John and I owe you big time.....:D The dropdownitems.add is the baby.

I didn't need the index as I already had the name of the menuitem. You are a genious. Thanks a shedload mon ami.

:cool:
 
Back
Top