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

Posted on 2012-09-13
Last Modified: 2012-09-13
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);
            this.listBox5.DataSource = ds1.Tables[0];
            this.listBox5.DisplayMember = "OfficeNumber";

How would I retrieve the specific value (OfficeNumber) selected from the listbox by the user?
Question by:zimmer9
    1 Comment
    LVL 13

    Accepted Solution

    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.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now