Populate Combobox in one column based on value of another column

2 posts, 0 answers
  1. StevenDale
    StevenDale avatar
    100 posts
    Member since:
    Apr 2007

    Posted 03 Sep 2009 Link to this post

    I have a grid that has 2 columns. Column one contains a Characteristic and column two contains a Value like:

    Characteristic | Value

    The second column of the grid for "Value" contains a ComboBox.

    The list of choices in the Value Column's ComboBox will depend on the Characteristic selected in Column 1.

    Is it possible to do this and if so could someone provide an example?


    Billy Jacobs 
  2. Rossen Hristov
    Rossen Hristov avatar
    2478 posts

    Posted 07 Sep 2009 Link to this post

    Hi Billy Jacobs,

    This can be achieved in the following way.

    1. Define two columns and their CellEditTemplates to contain a RadComboBox.
    2. Configure the "master" combo in a normal way.
    3. Attach to the "detail" combo's Loaded event, check what is the value of the master property and apply the appropriate ItemsSource.

    I have prepared a small sample project to demonstrate this. My business objects are football players. They have a general position:

    public enum Position

    and a SubPosition:

        public enum SubPosition

    So for example if you select that someone is a defender (DF) from the master combo, you will get only the defensive positions of left back (LB), right back (RB) and central defender (CD) in the second combo.

    And here is how to do this:

    <Window x:Class="TicketID_237419_CascadingCombos.Window1"  
        Title="Window1" Height="700" Width="600">  
                <local:Positions x:Key="Positions"/>  
            <telerik:RadGridView Name="playersGrid" Grid.Row="1" AutoGenerateColumns="False"  
                        DataMemberBinding="{Binding Name}">  
                        DataMemberBinding="{Binding Number}">  
                        DataMemberBinding="{Binding Country}">  
                        DataMemberBinding="{Binding Position}">  
                                    ItemsSource="{StaticResource Positions}"  
                                    SelectedItem="{Binding Position}"/>  
                        Header="Sub Position"   
                        DataMemberBinding="{Binding SubPosition}">  
                                    SelectedItem="{Binding SubPosition}"/>  

    And in the Loaded event handler we decide what to fill the combo with in the following manner:

    private void OnSubPositionsComboBoxLoaded(object sender, RoutedEventArgs e)  
                RadComboBox comboBox = (RadComboBox) sender;  
                Player player = (Player)comboBox.DataContext;  
                    case Position.GK:  
                        comboBox.ItemsSource = new GoalkeeperSubPositions();  
                    case Position.DF:  
                        comboBox.ItemsSource = new DefensiveSubPositions();  
                    case Position.MF:  
                        comboBox.ItemsSource = new MidfieldSubPositions();  
                    case Position.FW:  
                        comboBox.ItemsSource = new AttackingSubPositions();  

    You can find the full source code in the attached sample project. I hope it helps. Please let me know if you have any other questions.

    Best wishes,
    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