0

I have a combo box in my windows application form. I have a table called menu-list in a MySQL database. When i click on the combo box i want the options to be the value of a particular row of the database table for example a row called wine has 2 values, for example red wine and white wine, so when i click on the combo box i want the options to be red wine and white wine

private void menustart_Load(object sender, EventArgs e)
{
    // TODO: This line of code loads data into the 'cmsDataSet.menulist' table. You can move, or remove it, as needed.
    this.menulistTableAdapter.Fill(this.cmsDataSet.menulist);

}

I used the above code but it didnt work

1
  • igore that i was just copy pasting something from the net which didn't workout.. could you help me with an easier way to achieve my desired result Commented Mar 7, 2014 at 12:19

1 Answer 1

1

Maybe some of these posts might help you to get a solution :

Solution 1
Solution 2
Solution 3

Try these and let me know if you could find a solution.

EDIT : Try this code.

string MyConString = "SERVER=localhost;" +
                     "DATABASE=yourDB;" +
                     "UID=root;" +
                     "PASSWORD=yourPassword;";
MySqlConnection connection = new MySqlConnection(MyConString);
string command = "select wine from menu-list";
MySqlDataAdapter da = new MySqlDataAdapter(command,connection);
DataTable dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
   string wine = string.Format("{0}", row.Item[0]);
   yourCombobox.Items.Add(wine);
}
connection.Close();
Sign up to request clarification or add additional context in comments.

4 Comments

thanks alot worked perfectly as i wanted..there is another thing that i wanted to do.. could you tell me how to add these values retrived from the database as a checkbox option within a combobox.
@Brian I don't understand... What do you want to do ? Could you be more specific about your question ? Do you want to do the same for checkboxes ?
ya sure now in the solution which u provided every value from the database table is going into the combo box from which i can select only 1 value. i need to select multiple values from the combo box(ie try to 1st convert those values into a check box list and then but that check box list in the combo box) is that possible?? o is there any alternate solution
@Brian I think what you're trying to do might be solved here, it is using ComboBox, and they put some CheckBox within the ComboBox. codeproject.com/Articles/563862/Multi-Select-ComboBox-in-WPF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.