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

SelectedItem not working with Custom Class

1 Answer 45 Views
ListPicker
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
goodbar
Top achievements
Rank 2
goodbar asked on 05 Nov 2013, 06:11 AM

I am having an issue where I receive an "Value not within range of expected..." error upon loading my List.  My setup is that I have a list box with a data template.  Inside the data template is a RadListPicker.  The RadListPicker works great if I just bind to a simple list of strings, but when I try to bind to a custom class, I am not able to set the SelectedItem.


Here is an example of what actually works where CalendarColorOptions is a List<string> and CalendarColor is a String



<telerikInput:RadListPicker ItemsSource="{Binding CalendarColorOptions}" SelectedValue="{Binding CalendarColor, Mode=TwoWay}">

<telerikInput:RadListPicker.ItemTemplate>

<DataTemplate>

<StackPanel>

<TextBlock Text="{Binding}" />

</StackPanel>

</DataTemplate>

</telerikInput:RadListPicker.ItemTemplate>

<telerikInput:RadListPicker.PopupItemTemplate>

<DataTemplate>

<StackPanel

<TextBlock Text="{Binding}" />

</StackPanel>

</DataTemplate>

</telerikInput:RadListPicker.PopupItemTemplate>

</telerikInput:RadListPicker>




AND HERE'S AN EXAMPLE of what generates the error where CalendarColor is a custom class made of 2 properties (Color and ColorName).  CalendarColorOptions is a predefined List of CalendarColors.  When I bind the below I always receive the Value not within the expected range error, as if it does not know that CalendarColor exists in CalendarColorOptions.



<telerikInput:RadListPicker ItemsSource="{Binding CalendarColorOptions}" SelectedValue="{Binding CalendarColor, Mode=TwoWay}">    

<telerikInput:RadListPicker.ItemTemplate>

<DataTemplate>

<StackPanel Orientation="Horizontal">

<Border Background="{Binding Color, Converter={StaticResource ColorToSolidColorBrush}}" Height="30" Width="30" />

<TextBlock MinWidth="10" />

<TextBlock Text="{Binding ColorName}" />

</StackPanel>

</DataTemplate>

</telerikInput:RadListPicker.ItemTemplate>

<telerikInput:RadListPicker.PopupItemTemplate>

<DataTemplate>

<StackPanel Orientation="Horizontal">

<Border Background="{Binding Color, Converter={StaticResource ColorToSolidColorBrush}}" Height="30" Width="30" />

<TextBlock MinWidth="10" />

<TextBlock Text="{Binding ColorName}" />

</StackPanel>

</DataTemplate>

</telerikInput:RadListPicker.PopupItemTemplate>

</telerikInput:RadListPicker>




1 Answer, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 06 Nov 2013, 11:29 AM
Hello Joe,

Thanks for writing.

When using the SelectedValue property you will also need to instruct the RadListPicker control which property on your business object will be used in that context. For that purpose you should use the SelectedValuePath property and set the name of the property on your view model you would like to use as selected value.

Regards,
Deyan
Telerik
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
Tags
ListPicker
Asked by
goodbar
Top achievements
Rank 2
Answers by
Deyan
Telerik team
Share this question
or