views:

84

answers:

2

I'm used to doing things like

State.Items.Add(new ListItem { Text = "SomeState", Value = NumericIDofState });

Where State is a Listbox in ASP.NET.

How do i achieve the same with a WPF ComboBox? I do see a property called 'Content' in the ComboBoxItem object but how do i assign each item a value other than what's displayed to the user? Please help.

+2  A: 

See These properties of combo

DisplayMemberPath, SelectedValuePath.

saurabh
A: 

If you skip the Value, then I think it's quite simple to add a new item into a ComboBox at runtime.

comboBox1.Items.Add("SomeText");

comboBox1.SelectedIndex = comboBox1.Items.Count - 1;

The SelectedIndex property is set to Items.Count -1 so that the newly added item appears in the ComboBox as the selected item.

Mamta Dalal