Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

Microsoft Visual C# Combo box list items

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?
1 Solution
Pratima PharandeCommented:
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

BenvorAuthor Commented:
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
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.
BenvorAuthor Commented:
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
Maybe the problem is in your sql query which only return a single record.

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