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

Populating with Data

6 Answers 94 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Lilia
Top achievements
Rank 1
Lilia asked on 26 Jul 2011, 09:25 AM
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".

6 Answers, 1 is accepted

Sort by
0
Accepted
Valeri Hristov
Telerik team
answered on 26 Jul 2011, 09:30 AM
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!

0
Lilia
Top achievements
Rank 1
answered on 26 Jul 2011, 10:21 AM
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.
0
Valeri Hristov
Telerik team
answered on 26 Jul 2011, 10:29 AM
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!

0
Lilia
Top achievements
Rank 1
answered on 26 Jul 2011, 10:48 AM
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?
0
Accepted
Valeri Hristov
Telerik team
answered on 26 Jul 2011, 12:08 PM
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!

0
Lilia
Top achievements
Rank 1
answered on 26 Jul 2011, 01:11 PM
Thank you Valeri,

I used ClearSelectionButtonVisibility/Content and EmptyText for default value when the Clear button is clicked and it works for me.
Tags
ComboBox
Asked by
Lilia
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Lilia
Top achievements
Rank 1
Share this question
or