c# - WPF Combo box - Select Item by Tag -
i have combo box this
<combobox name="mymenu"> <comboboxitem content="question 1" tag="1" /> <comboboxitem content="question 2" tag="2" /> <comboboxitem content="question 3" tag="3" /> <comboboxitem content="question 4" tag="4" /> </combobox>
how can programmatically set selected index tag value? e.g. 'mymenu.selectedtag = 3' , question 3 selected item?
i want easier current solution really...
int tagtoselect = 3; foreach (comboboxitem item in mymenu.items) { if(item.tag.equals(tagtoselect) { mymenu.selecteditem = item; } }
looks you're looking proeprty selectedvaluepath of combobox control. see example here http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.selector.selectedvaluepath.aspx
Comments
Post a Comment