2

In this Load function have some hotel names,I wanted to bind that hotel names to Combo box. I go several steps but i'm having a problem in bind values to combo box from here.

private void myWindow_Load(object sender, EventArgs e)
{
    string new1 = f.Name; //hotel names comes here(eg:hilton,serandib)

    List<string> Hotels = new1 List<string>();
    Hotels.Add(new1);
    foreach (string Hotel in Hotels)
    {

    }
 }

Actually i want this hotel names show in combo box.(This is a windows form),Help me with the rest.

2
  • What is the error ? i think new is reserved keyword and you can not use it as a variable name! Commented Feb 13, 2013 at 5:44
  • stackoverflow.com/questions/3768328/… Commented Feb 13, 2013 at 6:09

4 Answers 4

2

You can make use of following code,

ComboBox1.DataSource = hotelList;

if you have following string coming from f.Name

"Le meridian, Fortune, Asiana"

    List<String> hotelList = f.Name.Split(',').ToList();

    ComboBox1.DataSource = hotelList;
Sign up to request clarification or add additional context in comments.

1 Comment

Just collect all the names in a list and bind it..as mentioned!
1
List<Hotels> Hname = new List<Hotels> { "Taj", " Star", "Poorna" ,"Settinad" };
comboBox.DataSource =  Hname;

or

List<Hotels> Hotel = new List<Hotels>();
Hotel.Add( "name");

comboBox.DataSource = Hotel;

Comments

1
        List<string> names = new List<string>();
        names.Add("name1");
        names.Add("name2");
        names.Add("name3");
        names.Add("name4");
        names.Add("name5");
        comboBox1.Items.Clear();
        foreach (string name in names)
        {
            comboBox1.Items.Add(name);
        }
        comboBox1.SelectedIndex = 0; //selects first item

Comments

1

You're about to add a items to ComboBox but actually you don't need use the List<string> to list the items to ComboBox, you can go it directly in .Items of ComboBox

 string new1 = f.Name; //hotel names comes here(eg:hilton,serandib)
 comboBox5.Items.Add(new1);

Comments

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.