Populating with Data

7 posts, 2 answers
  1. Lilia
    Lilia avatar
    32 posts
    Member since:
    Mar 2011

    Posted 26 Jul 2011 Link to this post

    Is there a way to populate RadComboBox from both ItemsSource and to set Items as well in the same time from xaml. I have an ItemsSource that gives me a list of names. I want to add to that list a value to 'Select All Names', maybe s.th. like that:

    <telerik:RadComboBox
       DisplayMemberPath="Name"
       ItemsSource="{Binding Source={StaticResource mySource}, Path=Model.Names}"
       SelectedValue="{Binding Value, Mode=TwoWay, FallbackValue=null}"
       SelectedValuePath="Name">
           <telerik:RadComboBox.Items>
              <telerik:RadComboBoxItem Content="Select All Names" IsSelected="True" />
           </telerik:RadComboBox.Items>
    </telerik:RadComboBox>

    So, if my  Model.Names returns a list with names like: { "Mini", "Miki", "Mouse"} I wat to add to that list a static item from xaml "Select All Names".

  2. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 26 Jul 2011 Link to this post

    Hi Lilia,

    RadComboBox is a regular ItemsControl hence it can be populated by either ItemsSource or Items, not both.

    All the best,
    Valeri Hristov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. DevCraft banner
  4. Lilia
    Lilia avatar
    32 posts
    Member since:
    Mar 2011

    Posted 26 Jul 2011 Link to this post

    Is there a way to set Default value for the RadComboBox. s.th. like Text="Default value"?
    I tried using this text property but my combobox is binded and that default value doesn't show.
  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 26 Jul 2011 Link to this post

    If you are looking for the EmptyText property, here is an example about it:
    http://demos.telerik.com/silverlight/#ComboBox/Configurator

    If this is not what you are looking for, I would need more information about you scenario in order to provide a correct advice.

    Regards,
    Valeri Hristov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. Lilia
    Lilia avatar
    32 posts
    Member since:
    Mar 2011

    Posted 26 Jul 2011 Link to this post

    Thank you Valeri for your fast reply!

    I want to do the following. Lets say that I have an object Person that has property Name and I want to bind my RadComboBox to a collection of person objects and display their Name. And I want to add a Default value for my ComboBox that say 'All Persons' and that value is not in my collection of Person objects. I want to add that value after my control has databind to my source, i.e. when I select some Name from the ComboBox I have the chance to select 'All Persons' again.

    I have another question about DisplayMemberPath property of the RadComboBox. In my example above I've set DisplayMemberPath="Name". Does that mean that the ComboBox doesn't load the whole collection of Person objects and load only their Name or not, i.e. the ComboBox loads all properties for the collection of Persons and then binds to their Names?
  7. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 26 Jul 2011 Link to this post

    Hi Lilia,

    RadComboBox does not have a feature that is similar to your request for "default value". The default value of the SelectedValue/SelectedItem properties is null and cannot be changed. If you are able to interpret this null so that it means "all" in the context of the application, you could use the ClearSelectionButtonVisibility/Content properties to configure a button that will reset the selection on click (see the link that I sent for a running example).

    The DisplayMemberPath just specifies which property of the data items in RadComboBox will be used in the UI to display the text of the control. The control cycles through the whole collection of data items and creates one RadComboBoxItem for each data item (unless you use a VirtualizingStackPanel as ItemsPanel - http://www.telerik.com/help/silverlight/radcombobox-howto-virtualization.html).

    Kind regards,
    Valeri Hristov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  8. Lilia
    Lilia avatar
    32 posts
    Member since:
    Mar 2011

    Posted 26 Jul 2011 Link to this post

    Thank you Valeri,

    I used ClearSelectionButtonVisibility/Content and EmptyText for default value when the Clear button is clicked and it works for me.
Back to Top
DevCraft banner