While I am trying to bind data to my combobox from an object on the designer,the Items are not displayed.
But they are displayed when I specify from the code behind...
How I can bind my collection from the designer??
While I am trying to bind data to my combobox from an object on the designer,the Items are not displayed.
But they are displayed when I specify from the code behind...
How I can bind my collection from the designer??
If you want to bind items from designer
Select -> Item Collection FROM Property Window
Add Programatically from list
List<string> values = new List<string>();
private void AddItemProg()
{
values.Add("Name");
values.Add("Age");
values.Add("DOB");
values.Add("Address");
comboBox1.Items.Clear();
for (int nIndex = 0; nIndex < values.Count; nIndex++)
{
string v = values[nIndex];
comboBox1.Items.Add(v);
}
}
You doesn't need use observablecollection to bind UI in windows form application. Just set the combobox.ItemSource = List<string>
. When you want to get current value just use combobox.SelectedItem or combobox.SelectedValue get current value.
(ps. observable property should have get and set method, in the set method you need call a method RaisePropertyChanged("propertyname")
, for that you also need do some change in UI part and import someting.(something like that, i don't remember exactly how it works, but it's complex.