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

SelectedItem DataTemplate not working

2 Answers 73 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Derek Ealy
Top achievements
Rank 1
Derek Ealy asked on 14 May 2010, 10:37 PM
Hi

I have a RadComboBox bound to an ObservableCollection<ColumnGroupViewModel> It looks like this:
                    <telerikInput:RadComboBox x:Name="cbxGroup" Margin="0,0,0,3" VerticalAlignment="Center"  
                                              d:LayoutOverrides="Height"  Width="195" 
                                              IsEnabled="{Binding Locked}" 
                                              ItemsSource="{Binding Groups, Mode=TwoWay}" 
                                              SelectedItem="{Binding SelectedGroup, Mode=TwoWay}" 
                                              LostFocus="cbxGroup_OnLostFocus" 
                                              Visibility="{Binding ColumnVisibility}" IsEditable="True"
                        <telerikInput:RadComboBox.ItemTemplate> 
                            <DataTemplate> 
                                <TextBlock Text="{Binding GroupName}"/> 
                            </DataTemplate> 
                        </telerikInput:RadComboBox.ItemTemplate> 
                    </telerikInput:RadComboBox> 
 
Groups is the ObservableCollection and SelectedGroup is a property returning the current ColumnGroupViewModel. ColumnGroupViewModel.GroupName is the string I want to be displayed in the dropdown and also in the editable area. However when my app runs it only displays the class name for ColumnGroupViewModel in the editable area. However all the proper GroupNames are displayed in the dropdown portion of the combobox.

I tried using SelectionBoxItemTemplate for the editable area but that just left the editable area blank. I don't see how to use a DataTemplate inside of an EditableTemplate so I'm lost here.

Any suggestions?

If I do get this working then my next question would be what does the RadComboBox do when the user types in a string value that doesn't match a GroupName in the ObservableCollection? Preferably I would like to catch this before an error and create a new ColumnGroupViewModel to add in the ObservableCollection with the newly specified value from the editable portion of the combobox.

Thanks, Derek


2 Answers, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 15 May 2010, 04:01 PM
Hello Derek,

To display the proper member value in the editable area you need to set the TextSearch.TextPath attached property:
http://demos.telerik.com/silverlight/#ComboBox/DataBinding

As for the second question, when you type text that does not match an item in the collection, the Text property will contain the typed text, but the SelectedItem/SelectedValue will be null. Since the Text property is updated in every key stroke, you will not be able to create new items without assigning a "create" key. Please, see the attached example for more info.

Kind regards,
Konstantina
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
Derek Ealy
Top achievements
Rank 1
answered on 17 May 2010, 04:48 PM
TextSearch.TextPath worked great.


Thanks!

Derek
Tags
ComboBox
Asked by
Derek Ealy
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Derek Ealy
Top achievements
Rank 1
Share this question
or