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

ItemTemplate inside CellEditTemplate with RadComboBox crashes

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

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:

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

<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:GridViewComboBoxColumn.CellEditTemplate>
                        <DataTemplate>
                            <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">
                                <telerik:RadComboBox.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <VirtualizingStackPanel Width="250" />
                                    </ItemsPanelTemplate>
                                </telerik:RadComboBox.ItemsPanel>                               
                            </telerik:RadComboBox>
                        </DataTemplate>
                    </telerik:GridViewComboBoxColumn.CellEditTemplate>
                </telerik:GridViewComboBoxColumn>

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.

Regards,
HÃ¥kan



1 Answer, 1 is accepted

Sort by
0
Yoan
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:

<telerik:GridViewComboBoxColumn.EditorStyle>
                       <Style TargetType="telerik:RadComboBox">
                           <Setter Property="ItemsPanel">
                               <Setter.Value>
                                   <ItemsPanelTemplate>
                                       <StackPanel/>
                                   </ItemsPanelTemplate>
                               </Setter.Value>
                           </Setter>
                           <Setter Property="IsFilteringEnabled" Value="True"/>
                       </Style>
</telerik:GridViewComboBoxColumn.EditorStyle>

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,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Håkan
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or