• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 477
  • Last Modified:

How would I retrieve the specific value selected from a listbox by the user using C# ?

I am developing a C# Windows platform application using VS 2005.

I set up a list box with the following statements:

DataSet ds1 = new DataSet();
            SqlDataAdapter adapter1 = new SqlDataAdapter("SELECT DISTINCT tblCustomersNew.OfficeNumber from tblCustomersNew order by OfficeNumber;", _conn);
            adapter1.Fill(ds1);
            this.listBox5.DataSource = ds1.Tables[0];
            this.listBox5.DisplayMember = "OfficeNumber";
            this.listBox5.ClearSelected();

How would I retrieve the specific value (OfficeNumber) selected from the listbox by the user?
0
zimmer9
Asked:
zimmer9
1 Solution
 
LIONKINGCommented:
Assign the ValueMember property to the name of the column you wish to return (i.e. OfficeNumber", then you can use the SelectedValue property to obtain that specific value.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now