By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,887 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,887 IT Pros & Developers. It's quick & easy.

Need a combobox with typed items

P: n/a
I need a combobox where the items are typed as string - not object.

And another where the items are from a class I generated.

Can one make such comboboxes from System.Windows.Forms.ComboBox?
If that is not practical I appreciate you telling me that?

Thanks in advance
Feb 19 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
active wrote:
I need a combobox where the items are typed as string - not object.

And another where the items are from a class I generated.

Can one make such comboboxes from System.Windows.Forms.ComboBox?
If that is not practical I appreciate you telling me that?

Thanks in advance

It would be possible to create a generic control to do this but...
1) is a cast acceptable at run time from the loosely typed items collection.
2) not sure how much luck you'd have validating item addition so you
might have to roll your own combo, not a trivial task i'd imagine
3) I dont think you have any way of creating generic controls with the
visual designer.

Experiment with creating a class such as:

public class ComboEx<T: System.Windows.Forms.ComboBox{
}

and go from there.

JB
Feb 19 '07 #2

P: n/a

"John B" <jb******@yahoo.comwrote in message
news:sP*******************@nasal.pacific.net.au...
active wrote:
>I need a combobox where the items are typed as string - not object.

And another where the items are from a class I generated.

Can one make such comboboxes from System.Windows.Forms.ComboBox?
If that is not practical I appreciate you telling me that?

Thanks in advance

It would be possible to create a generic control to do this but...
1) is a cast acceptable at run time from the loosely typed items
collection.
If I understand: That's what I want to get away from with the
Forms.ComboBox
2) not sure how much luck you'd have validating item addition so you might
have to roll your own combo, not a trivial task i'd imagine
You think if I did what you said below and added AddItem and AddItemRange
with typed arguments (and ignored the Item.Add and Item.AddRange) - sound
like it would work.

I just don't have much insight into this - which is why I'm asking.
Thanks
3) I dont think you have any way of creating generic controls with the
visual designer.

Experiment with creating a class such as:

public class ComboEx<T: System.Windows.Forms.ComboBox{
}

and go from there.

JB

Feb 19 '07 #3

P: n/a
active wrote:
"John B" <jb******@yahoo.comwrote in message
<...>
>>>
It would be possible to create a generic control to do this but...
1) is a cast acceptable at run time from the loosely typed items
collection.
If I understand: That's what I want to get away from with the
Forms.ComboBox
I agree but you are limited in the fact that you need to add the items
to the base combo's collection so it displays them.
You could keep another collection (strong typed) and just return that as
the items property but you'd need to ensure it was readonly or you'd
have to be notified when items are added.
>2) not sure how much luck you'd have validating item addition so you might
have to roll your own combo, not a trivial task i'd imagine

You think if I did what you said below and added AddItem and AddItemRange
with typed arguments (and ignored the Item.Add and Item.AddRange) - sound
like it would work.
It would work yes, but it depends on how much validation you want.
You would have to determine whether you wanted to absolutely prevent
adding to the items collection (by casting to combobox) or just
accept/hope that it would not happen.
There is a SetItemCore and SetItemsCore method but it appears they only
get called when you set a datasource.
JB
<...>
Feb 19 '07 #4

P: n/a
The combobox items are always objects. Everything in .Net is an object,
that's the cornerstone of the whole building.

Why not create a list and bind the combobox to the list? You can use
List(Of String) or List(Of Customers) to be specific.

Robin S.
-----------------------------------------
" active" <ac**********@a-znet.comwrote in message
news:ux**************@TK2MSFTNGP03.phx.gbl...
>I need a combobox where the items are typed as string - not object.

And another where the items are from a class I generated.

Can one make such comboboxes from System.Windows.Forms.ComboBox?
If that is not practical I appreciate you telling me that?

Thanks in advance


Feb 19 '07 #5

P: n/a
Per your last statement, I had searched the internet for "strongly typed"
ComboBox and got many hit - all seem to relate to datasource

Thanks for the help

Thanks
"John B" <jb******@yahoo.comwrote in message
news:lV*******************@nasal.pacific.net.au...
active wrote:
>"John B" <jb******@yahoo.comwrote in message
<...>
>>>>
It would be possible to create a generic control to do this but...
1) is a cast acceptable at run time from the loosely typed items
collection.
If I understand: That's what I want to get away from with the
Forms.ComboBox
I agree but you are limited in the fact that you need to add the items to
the base combo's collection so it displays them.
You could keep another collection (strong typed) and just return that as
the items property but you'd need to ensure it was readonly or you'd have
to be notified when items are added.
>>2) not sure how much luck you'd have validating item addition so you
might have to roll your own combo, not a trivial task i'd imagine

You think if I did what you said below and added AddItem and AddItemRange
with typed arguments (and ignored the Item.Add and Item.AddRange) - sound
like it would work.
It would work yes, but it depends on how much validation you want.
You would have to determine whether you wanted to absolutely prevent
adding to the items collection (by casting to combobox) or just
accept/hope that it would not happen.
There is a SetItemCore and SetItemsCore method but it appears they only
get called when you set a datasource.
JB
<...>

Feb 19 '07 #6

P: n/a

"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:A5******************************@comcast.com. ..
The combobox items are always objects. Everything in .Net is an object,
that's the cornerstone of the whole building.
I should have used "Object" instead of "object"
>
Why not create a list and bind the combobox to the list? You can use
List(Of String) or List(Of Customers) to be specific.
I'm going to look into this

thanks
>
Robin S.
-----------------------------------------
" active" <ac**********@a-znet.comwrote in message
news:ux**************@TK2MSFTNGP03.phx.gbl...
>>I need a combobox where the items are typed as string - not object.

And another where the items are from a class I generated.

Can one make such comboboxes from System.Windows.Forms.ComboBox?
If that is not practical I appreciate you telling me that?

Thanks in advance



Feb 19 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.