hi,
How to set the selectedvalue for combobox. For example i have some values from 1-10 and i want to select the 5th value.
I tried using SelectedValue and SelectedItem, But its not working for me.
Please reply
Thanks Sharath
hi,
How to set the selectedvalue for combobox. For example i have some values from 1-10 and i want to select the 5th value.
I tried using SelectedValue and SelectedItem, But its not working for me.
Please reply
Thanks Sharath
If you want to select "the fifth value", you should use SelectedIndex = 4 (since indexes are zero-based). If you want to select "the value 5", you should use SelectedValue = 5.
A ComboBox in WPF can select items in 3 ways. The first is to set SelectedIndex, where you set the zero-based index to an item. Another way is to to set a value with SelectedValue. Here you must add the value of the object you have selected. F.e. you have 3 comboboxitems {hello, bye, good morning}. So lets say you want to select bye you have to set SelectedValue = "bye". The last way ist to set the selected object by SelectedItem. There you have to set an ComboBoxItem or an XmlElement. You have to know that a combobox can contain ComboBoxItems and XmlElements. The behaviour is a bit differnt, but if you work with combobox some time you will understand it.
Hope this helps, greetings, Martin