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

SelectedItem issue

3 Answers 144 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Zarko Vorkapic
Top achievements
Rank 1
Zarko Vorkapic asked on 11 Nov 2009, 12:20 PM
Hi,

I've applied this datatemplate to a combobox itemtemplate

<DataTemplate x:Name="DataTemplateComboBoxMain"
            <Grid x:Name="GridDataTemplate"
                <TextBlock> 
                    <TextBlock.Text> 
                        <Binding Path="PostName"></Binding> 
                     </TextBlock.Text> 
                </TextBlock> 
                <TextBlock> 
                    <TextBlock.Text> 
                        , 
                     </TextBlock.Text> 
                </TextBlock> 
                <TextBlock> 
                    <TextBlock.Text> 
                        <Binding Path="PostCode"></Binding> 
                     </TextBlock.Text> 
                </TextBlock> 
            </Grid> 
        </DataTemplate> 

Dropdown list is populated ok, but when I select an item in a dropdown and it closes my selected item looks like MyClassLibrary.MyTypeName as you can see in an attached screenshots.

Combobox in XAML looks like

<telerik:RadComboBox x:Name="ComboBoxMain"  
        ItemTemplate="{StaticResources DataTemplateComboBoxMain}"  
        Height="25"  
        Width="Auto"  
        FilteringMode="None"  
        SelectionChanged="ComboBoxMain_SelectionChanged"   
        IsTextSearchEnabled="False"  
        IsEditable="True"  
        KeyUp="ComboBoxMain_KeyUp"
        </telerik:RadComboBox> 



Am I doing something wrong or is this another bug?

Regards,
Zarko

3 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 11 Nov 2009, 02:27 PM
Hi Zarko,

You need to set the TextSearch.TextPath attached property on RadComboBox, the same way we are doing it in our online sample (the last combo in the list):
http://demos.telerik.com/silverlight/#ComboBox/DataBinding

Sincerely yours,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Zarko Vorkapic
Top achievements
Rank 1
answered on 11 Nov 2009, 04:53 PM
Hi Valeri,

That example doesn't really help me. I need selected text to look exactly like the one in dropdown list, not just one property (like 'Name' in your example).

How can I accomplish this?

Thank you very much,
Zarko
0
Valeri Hristov
Telerik team
answered on 12 Nov 2009, 11:38 AM
Hello Zarko,

Unfortunately there is no way to customize RadComboBox to display several property values in its edit box. To achieve the display you want you need to create a property in your data class, which will combine the needed values. Something like this:
public class PostalInfo
{
    ...
    public string PostCodeAndName
    {
        get
        {
            return string.Format("{0}, {1}", this.PostCode, this.PostName);
        }
    }
    ...
}

Then set TextSearch.TextPath = "PostCodeAndName".

All the best,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ComboBox
Asked by
Zarko Vorkapic
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Zarko Vorkapic
Top achievements
Rank 1
Share this question
or