ToolstripComboBox

Moorzee

Well-known member
Joined
May 31, 2006
Messages
92
Location
England
Programming Experience
3-5
Has anyone ever used this as a normal combobox i.e with a diplsymember and valuemember?

I have been killing myself with this for a while now!

There is an underlying ComboBox which I have set datasource,displaymember, and valuemember but cannot use.......

Please someone put me out of my misery. Toes are curling up in frustration and grinding my teeth!!!:(

Ta.
 
As far as i know the toolstripcombobox is just a host for a normal combobox but you have to cast the the hosted control.

VB.NET:
Dim cb As ComboBox = DirectCast(toolStripComboBox1.Control, ComboBox)
cb.DataSource = someDataTable
cb.DisplayMember = "columname-for-text"
cb.ValueMember = "colunmname-for-values"
 
Right over my head that. Never seen directcast before.

Tried your suggestion vis,cheers,didn't fall over but nothing displayed in the toolstripcombobox on screen. Not my day:(
 
Really, i'm in shock! There's absolutley no reason why that shouldn't work. I'll look into it a bit more. It's just a combobox like any other. It inherits from the combobox class. I'd have to have a look and see what is going on under the hood to stop it from behaving correctly.
 
Right, 'tis a bug methinks. I can populate a toolstripcombo fine with your suggestion earlier(thanks vis) but only if the combo is at the top level on the toolstrip. This aint what I require. I'm looking to build a menu structure for searches so menu would be something along the lines of:
Clients:
--->Client Searches:
------>Search By Status(a tsCombo of statuses I have on DB)*PROB*
------>Search By Surname(A textbox to bung in a like%% param)
etc..

:confused: :( :( Gutted:( :( :confused:
 
I can't see why not. My menu would be logical. The parameter I require is a status(smallint) I populate a toolstripcombo with my status descriptions and valuemember of the code and as soon as the user selects a status from the toolstrip combo stored proc is fired and results returned.

Am I being mental?? :)
 
No, that sounds good to me. It's really that toolstrip combo that bugging me. I tried it last night and i couldn't get it to work. It doesn't make sense seeing as it's a normal combobox behind the scenes. But i did find a different solution on the web. It's not very elegant but it sounds like it could work....

Basically this guy had loaded the combobox manually in the forms constructor and created a private arraylist to hold the value member. Used the combobox to do a lookup of the valuemember in the arraylist and passed that to the tableadapter. It sounds a bit much, but apart from that there doesn't seem to be much else that you can do.
Bit of a pain, eh?
 
Basically this guy had loaded the combobox manually in the forms constructor and created a private arraylist to hold the value member. Used the combobox to do a lookup of the valuemember in the arraylist and passed that to the tableadapter. It sounds a bit much, but apart from that there doesn't seem to be much else that you can do.
Bit of a pain, eh?

I was thinking of something similar, but perhaps a bit sloppier, another combo populated at same time from a datareader, and made not visible then every selectedindexchanged event get the correspondoding value from the invisible combo.... Really should'nt have to though as you sai it is simply a combo whatever level of the structure you have it!!!:(
 
Just having another think. We know it works fine at the top level but not elsewhere. There really is no reason for this. Could you share you code for what your are trying to do?
 
I have got all the datasets and commands etc.. set up for my back end but you easily replicate by creating a top level combo populate with the cast and binding you put me on to then cut the control and embed further down a structure. Add a Dropdownbutton then a menuitem under that and place your combo across from this item!

No show?
 
I tried the same thing and can confirm that the items are not displayed. I checked the DataSource property of the control at various points and it was set to a table but no items were displayed. I have no idea why this would be the case but I'd agree that it must be a bug. You should report it to Microsoft but in the meantime you could get around it by just adding the items manually and using a keyed collection to setup the correspondence between the two properties if required.
 
I've reported the behaviour as a bug.
I've also implemented the idea of an array of int's to store my values and gained them from selectedindex of tstripcombo.
Whilst I'm here does anybody have any idea why when I select an option in my tstripcbo and code behind the SelectedIndexChanged event the menu structure stays visible, i.e still see the option under top level drpdownbtn, then the menuitem chosen then the actual cbo?

Is there a method I am missing a call to at the end of selection process to redraw the tstrip back to toplevel?

Cheers.
 
yeah, I click which ever row in my toolstripcombo and the selectedindexchanged event fires, my code is run(stored proc fired, results displayed in grid) but path taken to combo is still displayed from the toolstrip... Not particularly good english that I know.:eek:

Do you get what I am saying?

I have found that if I place a call to the toolstripcombo.PerformClick() event after my code has executed then the toolstrip is rendered as I would expect, no 2nd/3rd level items are displayed.
 
Back
Top