473,796 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2486
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******** ***********@nas al.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******** ******@TK2MSFTN GP03.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******** ***********@nas al.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.ComboB ox
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******** ******@TK2MSFTN GP03.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
5791
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 want to remove items from the items collection of the combobox if they are in my array. Here is what i try If i > 0 The For i= 0 To (MyArray.Count - 1 Combobox1.Items.Remove(MyArray Next End I
17
2677
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 cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
5
5917
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 CompanyID's. The second combobox will contain unique memberID's. Each of the tables that I have to search contain a CompanyID and a memberID field, and these fields are not unique in the respective tables. Like CompanyID, MemberID
1
2100
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 works. The first set of code I downloaded from internet and when i tried it, it worked fine. But when I changed the second part of the code it started to give me trouble. Before I changed the code they used Datacolumns,Datarows and Datatables and...
1
1153
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 a leading zero if the number is less than 10. The problem with this is that if I try to input '01' I'll simply jump to a number that starts with a zero. If I try to put in '02' or '2', I get '20'. Is there something I'm missing here?
19
2209
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 like Text replaces an item or something like that. This results in a runtime error at which time I learn that the item that should be CQQ is a String.
1
1758
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") CallByName(Form1.Controls("ComboBox" & i), "items.add", Type.Set, "3rd item") next Is there a way I can populate these 3 combo boxes using the CallByName feature. My form has 3 combo boxes named ComboBox1, ComboBox2, ComboBox3. I would really Prreeeeeeciate your...
4
6667
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 common/standard .NET control accepting an Object as a parameter type? In Web Forms, there is a ListItem object that can be passed in to add/retrieve objects from a DropDownItems collection. I searched Google groups, and all the solutions I'm finding...
2
4115
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 objxmldoc.Load("s:\sw7\nc\custnum.xml") Dim onode As Xml.XmlNode Dim custNum As Xml.XmlNodeList custNum =
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9528
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10006
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9052
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.