SelectionBoxItemTemplate issue

3 posts, 1 answers
  1. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 12 May 2009 Link to this post

    Hello,

    Based on one of your examples I created a RadComboBox in which I want to display certain information when the comboBox (Name, Site, Department) is open and when one item is selected the comboBox displays only the Name.

    I created the corresponding templates, and it displays the list correctly, but when one item is selected the ComboBox shows the class name that I'm binding to the control.

    Please, let me know what I'm missing.   I'm using IE7, and the version of my controls is 2009.1.508.1020  (I had to use this internal release since I needed to solve an issue with rearranging grid columns contained in RadWindows)

    1 <UserControl x:Class="Intel.Cqn.FamisLight.Silverlight.UserControls.EmployeeSearch" 
    2     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      
    4     xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" 
    5     >     
    6     <Grid x:Name="LayoutRoot" Background="White">     
    7         <Grid.Resources>             
    8             <DataTemplate x:Key="ComboBoxCustomTemplate"
    9                 <StackPanel Orientation="Vertical"
    10                     <TextBlock FontWeight="Bold" Grid.ColumnSpan="2" Text="{Binding Name}" /> 
    11                     <StackPanel Orientation="Horizontal"
    12                         <TextBlock Foreground="RoyalBlue" Text="Department: " /> 
    13                         <TextBlock Text="{Binding Department}" /> 
    14                         <TextBlock Foreground="RoyalBlue"  Text="  Site: " /> 
    15                         <TextBlock Text="{Binding Site}" /> 
    16                     </StackPanel>                         
    17                 </StackPanel>                 
    18             </DataTemplate> 
    19             <DataTemplate x:Key="ComboBoxSimpleTemplate">                 
    20                 <TextBlock Text="{Binding Name}" />                 
    21             </DataTemplate> 
    22         </Grid.Resources>         
    23         <telerik:RadComboBox Name="LookupComboBox" 
    24                              IsEditable="True" 
    25                              ItemTemplate="{StaticResource ComboBoxCustomTemplate}" 
    26                              SelectionBoxItemTemplate="{StaticResource ComboBoxSimpleTemplate}"                              
    27                              >              
    28         </telerik:RadComboBox> 
    29     </Grid> 
    30 </UserControl> 

    Thanks very much for your help,
    Marco



  2. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 13 May 2009 Link to this post

    Hi Marco,

    When the IsEditable property is set to True RadComboBox uses different control template, which puts a TextBox in the selection box area, hence the SelectionBoxItemTemplate is not used anymore. To display the value of a property of your data object you need to use the TextSearch.TextPath attached property. Here is the updated RadComboBox declaration (note that I changed the xml namespaces):
    <UserControl x:Class="SilverlightApplication1.SilverlightControl1"
      xmlns="
    http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="
    http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
      xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input">
     <Grid x:Name="LayoutRoot" Background="White">
      <Grid.Resources>
       <DataTemplate x:Key="ComboBoxCustomTemplate">
        <StackPanel Orientation="Vertical">
         <TextBlock FontWeight="Bold" Grid.ColumnSpan="2" Text="{Binding Name}" />
         <StackPanel Orientation="Horizontal">
          <TextBlock Foreground="RoyalBlue" Text="Department: " />
          <TextBlock Text="{Binding Department}" />
          <TextBlock Foreground="RoyalBlue" Text="  Site: " />
          <TextBlock Text="{Binding Site}" />
         </StackPanel>
        </StackPanel>
       </DataTemplate>
      </Grid.Resources>
      <telerikInput:RadComboBox Name="LookupComboBox" IsEditable="True"
        ItemTemplate="{StaticResource ComboBoxCustomTemplate}"
        telerik:TextSearch.TextPath="Name">
      </telerikInput:RadComboBox>
     </Grid>
    </UserControl>


    Sincerely yours,
    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Marco
    Marco avatar
    23 posts
    Member since:
    Apr 2009

    Posted 13 May 2009 Link to this post

    Cool, it works perfectly!
    Thanks Valeri for your precise and timely response! :)
Back to Top