Microsoft Visual C# Combo box list items

Posted on 2009-02-20
Last Modified: 2013-11-27
Hi experts, I have a combo box with data bound items, I have a Town table like this:

Town ID  = 7
Town description  = Demo Town

there are about 10 towns, and the combo box only displays the current selected record of my database...

How do i list all 10 towns inside of the combo box?
Question by:Benvor
    LVL 39

    Accepted Solution

    Not sure I got your qestion or not .
    can you explain bit n=more?

    Normal Combo box binging code is like this

       string strConnectionString = "connetion string here"; 
        SqlConnection cnn = new SqlConnection(strConnectionString); 
        SqlClient.SqlCommand cmd = new SqlClient.SqlCommand("SELECT * FROM table ", cnn); 
        cmd.CommandType = CommandType.Text; 
        SqlClient.SqlDataAdapter dacmd = new SqlClient.SqlDataAdapter(cmd); 
        DataSet dscmd = new DataSet(); 
       DropDownList1.DataSource = ddDR;
    DropDownList1.DataTextField = "DisplayValueFieldFromDB";
    DropDownList1.DataValueField = "DataValueFieldFromDB";

    Open in new window


    Author Comment

    The combo box displays the correct info, but there is only 1 item in the list at a time, and i want to display the whole list of towns inside the combo box
    LVL 15

    Expert Comment

    What code are you using to set the data the combio box should use?  It seems like you may be just returning 1 value from the database and using that to populate the combo box.

    Author Comment

    I'm not using any code, that results I get from just selecting the "ComboBox tasks/Use data bound items" and selecting the appropriate binding source
    LVL 13

    Expert Comment

    Maybe the problem is in your sql query which only return a single record.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    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…

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now