• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • 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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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