c# - Check if a ComboBox Contains Item -


i have this:

<combobox selectedvaluepath="content" x:name="cb">   <comboboxitem>combo</comboboxitem>   <comboboxitem>box</comboboxitem>   <comboboxitem>item</comboboxitem> </combobox> 

if use

cb.items.contains("combo") 

or

cb.items.contains(new comboboxitem {content = "combo"}) 

it returns false.

can tell me how check if comboboxitem named combo exists in combobox cb?

items itemcollection , not list of strings. in case collection of comboboxitem , need check content property.

cb.items.cast<comboboxitem>().any(cbi => cbi.content.equals("combo")); 

or

cb.items.oftype<comboboxitem>().any(cbi => cbi.content.equals("combo")); 

you can loop on each item , break in case found desired item -

bool itemexists = false; foreach (comboboxitem cbi in cb.items) {     itemexists = cbi.content.equals("combo");     if (itemexists) break; } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -