Reputation: 91
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.
Upvotes: 2
Views: 3646
Reputation: 7082
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);
Upvotes: 1
Reputation: 2497
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
Upvotes: 1
Reputation: 27
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;
Upvotes: 1
Reputation: 6490
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;
Upvotes: 2