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

ItemTemplate inside CellEditTemplate with RadComboBox crashes

1 Answer 125 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Håkan asked on 29 Nov 2012, 11:34 AM

I have a pretty advanced template for a GridViewComboBoxColumn that displays projects.

I would like to have a two column combobox (Project number and name) both in the dropdown and when not in editing mode.
I also need to capture the SelectionChange event of the ComboBox.

As now the multi column only works when not in editing mode, the drop down only displays the name.
And that is because I can't include the ItemTemplate, it will crash when I open the drop down.

My working xaml looks like this:

                <DataTemplate x:Key="ProjectDataTemplate">
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="*" />
                        <TextBlock Text="{Binding Number}" TextAlignment="Right" Margin="0,0,5,0" />
                        <TextBlock Text="{Binding Name}" Grid.Column="1" />

<telerik:GridViewComboBoxColumn Header="Projekt" IsComboBoxEditable="True" DataMemberBinding="{Binding ProjectId}" ItemsSource="{Binding Path=Projects, Source={StaticResource ViewModel}}" SelectedValueMemberPath="ProjectId" DisplayMemberPath="Name" ItemTemplate="{StaticResource ProjectDataTemplate}" Width="*">
                            <telerik:RadComboBox SelectedValue="{Binding ProjectId, Mode=TwoWay}" ItemsSource="{Binding Path=Projects, Source={StaticResource ViewModel}}" DisplayMemberPath="Name" SelectedValuePath="ProjectId" IsEditable="True" TextSearchMode="Contains" IsReadOnly="True" OpenDropDownOnFocus="True" SelectionChanged="ProjectChanged">
                                        <VirtualizingStackPanel Width="250" />

When I add <telerik:RadComboBox.ItemTemplate> inside the RadComboBox tag, with the data template in the resource above it crashes.

What am I doing wrong?

It would also be nice to use the IsFilterable flag, but as I understood it does not work when virtualizing is on.
I tried to shut it off by setting EnableColumnVirtualization and EnableRowVirtualization to false, but there was no difference.
I also replaced the VirtualizingStackPanel with a normal StackPanel, but I didn't get that to work either.


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 04 Dec 2012, 09:30 AM
Hello Håkan,

 I have prepared a sample project for you. You can find it attached. As you can see the multi comboBoxColumn is working when the dropdown is open and when the column is not in editing mode. 

Actually, when setting  the properties EnableColumnVirtualization and EnableRowVirtualization to False, you do not turn off the virtualization of GridViewComboBoxColumn. If you want to turn it off you can add this style to the ComboBoxColumn:

                       <Style TargetType="telerik:RadComboBox">
                           <Setter Property="ItemsPanel">
                           <Setter Property="IsFilteringEnabled" Value="True"/>

If you want to capture the SelectionChange event of the ComboBox, you may add a handler for the SelectionChanged event as follows:
this.RadGridView1.AddHandler(RadComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(OnSelectionChanged));
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
    // TODO: Implement this method
    throw new NotImplementedException();

Kind regards,
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question