Combo box Default Selected Item/Value?

5 posts, 1 answers
  1. Alex
    Alex avatar
    141 posts
    Member since:
    Mar 2010

    Posted 03 Sep 2010 Link to this post

    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)
  2. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 08 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. Alex
    Alex avatar
    141 posts
    Member since:
    Mar 2010

    Posted 08 Sep 2010 Link to this post

    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.
  5. HaukiDog
    HaukiDog avatar
    2 posts
    Member since:
    May 2006

    Posted 22 Oct 2010 Link to this post

    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
  6. George
    Admin
    George avatar
    1332 posts

    Posted 27 Oct 2010 Link to this post

    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
Back to Top
DevCraft banner