473,394 Members | 1,935 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,394 software developers and data experts.

assign value to combobox

hi there
i am having some difficulties to bind value to combobox in windows application.

combo.Items.Add(new List("a","b"))

I have created a class.
The value is there but what is displayed is the class name. How should i display a value from he value i have keyed in. For instance i want to display 'a'
Nov 7 '08 #1
8 3958
vanc
211 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. combo.Items.Add("a");
Is that what you want?
Nov 7 '08 #2
Expand|Select|Wrap|Line Numbers
  1. combo.Items.Add("a");
Is that what you want?
nope. Well i want a displayed in my combobox. But i also want to assign a value to a . for instance 1.

so when i click on 'a' the value is 1
Nov 7 '08 #3
tlhintoq
3,525 Expert 2GB
nope. Well i want a displayed in my combobox. But i also want to assign a value to a . for instance 1.

so when i click on 'a' the value is 1
You need to realize there is a separation between those two things.
For 'a' to have a value, then 'a' is a variable.
For you to display something in a combo box it needs to be a string.

You may want to investigate Dictionary<>
Basically its a 2d array. You could put the key into your combobox then use it's value elsewhere in your program.
Nov 7 '08 #4
r035198x
13,262 8TB
This is a bit of a nuisance with the Combobox. Basically the specs say you can add an object too to the combobox. The value displayed will be the ToString() of that object. So you may need to create a small class that holds the value and override it's ToString to return the display text.
Nov 7 '08 #5
tlhintoq
3,525 Expert 2GB
This is a bit of a nuisance with the Combobox. Basically the specs say you can add an object too to the combobox. The value displayed will be the ToString() of that object. So you may need to create a small class that holds the value and override it's ToString to return the display text.
Cool. I didn't know that one. Will have to try it some time. Thanks!
Nov 10 '08 #6
r035198x
13,262 8TB
Cool. I didn't know that one. Will have to try it some time. Thanks!
Like I said, the whole thing is quite a nuisance. Creating a class just so you can have name, value pairs.
Nov 10 '08 #7
vanc
211 Expert 100+
nope. Well i want a displayed in my combobox. But i also want to assign a value to a . for instance 1.

so when i click on 'a' the value is 1
You can use 2 combo boxes, one to hold "a" while the other will hold "1" accordingly. Then you make IndexChanged event that will synchronize those two combo boxes, so everytime you pick "a" in the first box, the second box will be "1". Just an idea to get around it. :D
Nov 11 '08 #8
r035198x
13,262 8TB
You can use 2 combo boxes, one to hold "a" while the other will hold "1" accordingly. Then you make IndexChanged event that will synchronize those two combo boxes, so everytime you pick "a" in the first box, the second box will be "1". Just an idea to get around it. :D
Not very efficient memory and performance wise I have to say. Especially if more than one comboboxes are required. The advantage of creating that class to hold the values is that you (normally) only need one class for all your comboboxes.
Nov 11 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
6
by: Matt | last post by:
I'm not entirely sure how to describe this issue. I have a number of ComboBoxes in my application which have their text properties bound to a field in a data set. The items loaded in the ComboBox...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
5
by: Anil Gupte | last post by:
I am trying to use a dataset to assign a display name (one column from a table) and also associate a value (2nd column) to each item in a dropdown combobox. I tried it this way: ...
1
by: sfindlay | last post by:
I have two comboboxes in an unbound field: - finds Vendor ID, and from this list finds Application ID using Vendor ID as the filter. The application details are populated in a subform bound...
0
by: divyabhasin | last post by:
HI I want to assign a specific value to an item in combobox and want that value to be entered in database instead of the selected item. For Ex- In the Combobox I have selected "PlayFile"...
2
by: DesCF | last post by:
I have a textbox and a combobox on a toolstrip. The user enters either an ID in the textbox or selects a name from the combobox. When the user selects a name from the combobox the textbox is...
4
by: hhak | last post by:
Hi all, Im pretty new to C#, im trying to assign a combobox selected value to a int variable. int number; combobox has items added (1,2,3,4,...9) when i select a number from the combobox i...
1
Plater
by: Plater | last post by:
I feel like this question has been asked before, but I couldn't find it. I think I am missing something obvious. Basically I am going to have a DataGridView with two columns. One textbox, one...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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.