473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Need a combobox with typed items

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
6 2462
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

"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
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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Varun | last post by:
Hello I am trying to make the items in my combobox be removed if they are present in my array I cant however get my code to work. The values are read into my combobox using a datareader. I then...
17
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
1
by: fiaolle | last post by:
Hi The first set of source code is the class for a combobox in a grid, hopefully. In the second set of code we try to use the combobox class, but the grid is empty. I don't understand how this...
1
by: sherri | last post by:
I currently have a combo box that will jump to a selection when the user inputs some text. The problem I am having is this. The 2-digit numerical values displayed in the combo box are padded with...
19
by: active | last post by:
I'm using a ComboBox to display objects of a class I've defined, say CQQ. Works great except somehow I occasionally set an Item to a String object instead of an object of type CQQ. It looks...
1
by: Timberwoof | last post by:
For i = 1 To 3 CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "1st item") CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "2nd item")...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
2
by: spowel4 | last post by:
Here's my code thus far: Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim objxmldoc As New Xml.XmlDataDocument() 'Load all customer numbers...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.