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

How do I retrieve the selected value from a combobox?

3
As shown below, I've filled a customer combobox with a customer id (named intItem) and customer name (named strItem).
What would be the syntax to get the intItem after the user makes a selection?

Expand|Select|Wrap|Line Numbers
  1.             while (rsCustomer.Read())
  2.             {
  3.                 // Load Customer Names into combobox.
  4.                 intItem = Convert.ToInt32(rsCustomer["CustomerID"].ToString());
  5.                 strItem = rsCustomer["CustomerName"].ToString();
  6.                 Customer item = new Customer(intItem, strItem);
  7.                 cboCustomerName.Items.Add(strItem);
  8.             }
Oct 14 '09 #1
5 6452
GaryTexmo
1,501 Expert 1GB
There should be a SelectedItem or SelectedIndex property on the combo box...

Yep, there's several available to you. Check it out here :)
http://msdn.microsoft.com/en-us/libr...x_members.aspx
Oct 14 '09 #2
mondo3
3
Thanks for trying, but
cboCustomerName.SelectedItem.ToString()
would show the customer's name, but not the CustomerID which is what i need. and before you ask,
cboCustomerName.SelectedValue.ToString() gives an error message.
what i really need is a way to separate item back into strItem and intItem
Oct 14 '09 #3
GaryTexmo
1,501 Expert 1GB
Oh!

I can take a more detailed look when I get home, but let me say this. You get out of a combo box what you put in. You put a string in, so that's what you're going to get out. The combo box will display in it whatever the .ToString() evaluates to be, but you can put anything you like in there (I think, not 100% sure at this time).

I gotta run... hopefully that gives you some ideas, I'll try to get back to you shortly.
Oct 14 '09 #4
mondo3
3
thanks...in re-reading the code i posted i noticed that it should have been
cboCustomer.Items.Add(Item)
then the following code gave me the result I needed:

int intCustomerID=((Customer)cboCustomerName.SelectedI tem).CustomerID;

Thanks for your help!
Oct 14 '09 #5
GaryTexmo
1,501 Expert 1GB
Ah good, I'm glad you got it figured out. I probably should have seen that before, but I thought you were asking how to get it out period, not how to get the specific value.

Happy coding :)
Oct 14 '09 #6

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

Similar topics

2
by: JC | last post by:
Hi, I am having a very difficult time retrieving the value of the selected item in the combo box using ASP. I have the following code, that refreshes the page location when the combo box...
6
by: Mendhak | last post by:
Hi All, When you add an object to a combobox, and run the application, you'll get something like this: System.Windows.Forms.Button, Text: Button1 (for example). Is it possible to have...
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...
2
by: farseer | last post by:
Hi, I have a combobox who's data source i set to an array of objects (call it MyObject). these objects have get properties: key, value, descr. i set ValueMember to "key", DisplayMember to...
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...
4
by: rang1 | last post by:
Hi, My VB.Net 2005 application is throwing the following exception when I try to retrieve the selected item from a combobox. Conversion from type 'DataRowView' to type 'String' is not valid ...
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
by: BASSPU03 | last post by:
I've set my combobox to operate according to this option: "Find a record on my form based on a value I selected from my combobox." When I select a value from the combobox, I can see that the...
1
by: sbandalli | last post by:
Hello, I have a Datagridview which has a combobox,and 2 textbox, The combobox is bound to a Datasource(Database Sql Server and the table name is Category) ,and Datagridview is not bounded to any...
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?
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
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
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
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.