tags:

views:

43

answers:

2

Hi All,

I am using the following code to display items in the combobox. but item is not getting displayed.

Code:

<ComboBox Width="100" ItemsSource="{Binding}" SelectedIndex="0" Name="cbProduct"/>
  List<ComboObject> combObjList = new List<ComboObject>();

        combObjList.Add(new ComboObject { Text = "All", Value = "%" });
        combObjList.Add(new ComboObject { Text = "Music", Value = "1" });
        combObjList.Add(new ComboObject { Text = "Games", Value = "2" });
        combObjList.Add(new ComboObject { Text = "Video", Value = "3" });

        cbProduct.DataContext= combObjList;
        cbProduct.DisplayMemberPath = "Text";
        cbProduct.SelectedValuePath = "Value"; 
A: 

Make sure that the properties you are binding to have a 'get' defined.

public ObservableCollection<ComboObject> CombObjList
    {
        get { return combObjList; }
    }
    private ObservableCollection<ComboObject> combObjList = new ObservableCollection<ComboObject>();

class ComboObject
{
    public string Text { get; set; }
    public string Value { get; set; }
}

Also, take a look at your 'Output' window do see if you are having any Binding errors.

Hope this helps!

JSprang
A: 

Have you Tried DisplayMemberPath attribute on Combo Box?

Shoaib Shaikh