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

GridViewComboBoxColumn different dropdown/selected values

4 Answers 543 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Timothy
Top achievements
Rank 1
Timothy asked on 13 Aug 2013, 04:18 PM
I have a GridViewComboBoxColumn inside a RadGridView. The GridViewComboBoxColumn is bound to a collection of Objects. I need to display different things for the selected option vs the dropdown options. I would like to display one property of the Object in the selection box (object.Name), and another property in the drop down (Object.Description).

I accomplished this in a RadComboxBox before by doing the following:
<telerik:RadComboBox Grid.Row="2" Grid.Column="1" telerik:StyleManager.Theme="Windows8Touch" Margin="5 3 5 0" MaxDropDownHeight="1000"
                     ItemsSource="{Binding MultiCropTypes}" SelectedValue="{Binding SelectedMultiCropTypeId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                     Tag="{Binding MultiCropTypes}" SelectedValuePath="PkMultiCropTypeId">
    <telerik:RadComboBox.SelectionBoxTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Description, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" TextTrimming="CharacterEllipsis" />
        </DataTemplate>
    </telerik:RadComboBox.SelectionBoxTemplate>
    <telerik:RadComboBox.ItemTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" TextWrapping="Wrap" Width="900" Margin="0,0,10,0" />
        </DataTemplate>
    </telerik:RadComboBox.ItemTemplate>
</telerik:RadComboBox>

I can't do this for a GridViewComboBoxColumn because there is no "SelectionBoxTemplate" property.

Is it possible to get the same behavior in a GridViewComboBoxColumn? Any help would be greatly appreciated. Thank you.

4 Answers, 1 is accepted

Sort by
0
Timothy
Top achievements
Rank 1
answered on 13 Aug 2013, 07:07 PM
Half Solution:

<telerik:GridViewDataColumn Header="Multi-Crop" Width="125">
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <telerik:RadComboBox telerik:StyleManager.Theme="Windows8Touch" Margin="5 3 4 0" MaxDropDownHeight="1000" GotFocus="RadComboBox_SelectionChanged"
                                 ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.MultiCropTypes}" SelectedValue="{Binding SelectedMultiCropTypeId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
                                 Tag="{Binding RelativeSource={RelativeSource AncestorType=UserControl},Path=DataContext.MultiCropTypes}" SelectedValuePath="PkMultiCropTypeId">
                    <telerik:RadComboBox.SelectionBoxTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" TextTrimming="CharacterEllipsis" />
                        </DataTemplate>
                    </telerik:RadComboBox.SelectionBoxTemplate>
                    <telerik:RadComboBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Description, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" TextWrapping="Wrap" Width="900" Margin="0,0,10,0" />
                        </DataTemplate>
                    </telerik:RadComboBox.ItemTemplate>
                </telerik:RadComboBox>
            </Grid>
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>

Doing this allows for my requested behavior but when user tabs to cell, the menu doesn't dropdownonfocus. Now I have to specify a CellTemplate and a EditCellTemplate. And they would both be the same thing. This seems wasteful. Any suggestions?
0
Yoan
Telerik team
answered on 14 Aug 2013, 02:29 PM
Hello Timothy,

Indeed, the editor of GridViewComboBoxColumn is RadComboBox. So, you can try set Column's editor style like so:

<telerik:GridViewComboBoxColumn.EditorStyle>
     <Style TargetType="telerik:RadComboBox">
         <Setter Property="SelectionBoxTemplate">
                <Setter.Value>
                             .
                             .
                             .
                      </Setter.Value>
               </Setter>               
     </Style>
</telerik:GridViewComboBoxColumn.EditorStyle>


Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Timothy
Top achievements
Rank 1
answered on 06 Sep 2013, 03:14 PM
Yoan,

  Thank you for the reply. I tried your suggestion and it works, half way. After implementing your suggestion the combobox is only displaying the correct format when I select the cell. If the cell isn't selected then the combobox does not display the correct format. This brings me back to my original problem, having to declare both a CellTemplate and a CellEditTemplate. Any ideas? Thanks.

 -Tim
0
Yoan
Telerik team
answered on 11 Sep 2013, 10:29 AM
Hello Tim,

Generally, if you want to open the DropDown when the RadCombobox gets focus, you can set its OpenDropDownOnFocus property to True. However, I have prepared a sample project showing you how to set GridViewComboBoxColumn's SelectionBoxTemplate and ItemTemplate. Please find it attached.

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Timothy
Top achievements
Rank 1
Answers by
Timothy
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or