This is a migrated thread and some comments may be shown as answers.

Combo box Default Selected Item/Value?

4 Answers 101 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 03 Sep 2010, 07:44 AM
Is there a way to set a ComboBox's default selected item?


In my round about away of trying to achieve this, I tried to use the Clear Selection Button, and overrode the Setter in my bound property (if value == null, use set value to default value). So in my model, it works fine, however, in the UI layer it doesn't, as the selected item is null (even thou the bound value is correct)
i.e. The control doesn't update correctly


e.g. If I have it bound to a collection of strings

{ bill, john, maxine }
And John is currently selected, but Maxine is the default.
In my properties setter I would so something like this

newValue = value;
if (newValue == null) newValue = default; (where default is Maxine)
...
RaisePropertyChanged...etc.

Now if I call from codebehind, property = null
It will correctly set the property to the default value, and the Combo box will properly select Maxine
However, if I click the clear selection button, it will set the value to null, which thus causes the value to be set to Maxine, BUT, the control still has it's currently selected item to null


i.e. I suspect your control does this when you clear selection
*set binded property to null
*privately set selected item to null - and do not persist changes to binding
Is it possible that you could rectify this in a future version?
(e.g. privately set selected item to null, then set binded property to null)

4 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 08 Sep 2010, 01:05 PM
Hi Alexander,

I created a simple application that resembles my understanding of your scenario. It seems to work as expected, could you please, let me know if I am doing something wrong?

Best wishes,
Valeri Hristov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 09 Sep 2010, 03:19 AM
Hi Valeri,

Yes that is what I was trying to do, I'm not to sure why mine was not working before... thou I've re-written it and it seems to work fine.
0
HaukiDog
Top achievements
Rank 1
answered on 22 Oct 2010, 08:33 PM
I just tried this sample code in SL4 with the latest Telerik libraries and it doesn't work. It allows me to click 'clear' only if I have not selected any previous value. Once I make a selection in the list clear seems to have no effect.

Any idea?

-Dave
0
George
Telerik team
answered on 27 Oct 2010, 02:32 PM
Hello Dave,

I tried to reproduce the problem, but to no avail. In the previous example is shown how to set a default value of the RadComboBox when the Clear button is clicked. Please, let me know if I missed something. Could you please give some more details about the issue? 

I will be glad to assist you further.

Greetings,
George
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
Alex
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Alex
Top achievements
Rank 1
HaukiDog
Top achievements
Rank 1
George
Telerik team
Share this question
or