SelectedItem issue

4 posts, 0 answers
  1. Zarko Vorkapic
    Zarko Vorkapic avatar
    18 posts
    Member since:
    Sep 2009

    Posted 11 Nov 2009 Link to this post

    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
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 11 Nov 2009 Link to this post

    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.
  3. Zarko Vorkapic
    Zarko Vorkapic avatar
    18 posts
    Member since:
    Sep 2009

    Posted 11 Nov 2009 Link to this post

    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
  4. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 12 Nov 2009 Link to this post

    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.
Back to Top