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

How to deal with GridViewDataColumn.CellTemplate and virtualization

7 Answers 730 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jose Simas
Top achievements
Rank 2
Jose Simas asked on 20 Oct 2010, 10:52 AM
Hi,

Given the grid below:

<my:RadGridView 
            x:Name="grdData"
            VerticalAlignment="Stretch"
            ItemsSource="{Binding List}"
            ShowGroupPanel="False"
            AutoGenerateColumns="False"
            EditTriggers="None"
            CanUserSelect="False"
            Tag="{Binding ComboBoxList}"
            >
            <my:RadGridView.Columns>
                <my:GridViewDataColumn Header="Variable" TextAlignment="Center">
                    <my:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox 
                                ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, 
                                                AncestorType={x:Type my:RadGridView}, AncestorLevel=1}, Path=Tag}"
                                SelectedValuePath="Value"
                                DisplayMemberPath="Name"
                                SelectedValue="{Binding SelectedItem}"
                                />
                        </DataTemplate>
                    </my:GridViewDataColumn.CellTemplate>
                </my:GridViewDataColumn>
            </my:RadGridView.Columns>
        </my:RadGridView>

Which is a grid with a single column which has a custom datatemplate with a combobox in it. Each item in the list has a value assigned (no ComboBox is empty).

When the list is long and the vertical scrollbars are visible, if I drag the scrollbar down, hiding a few items at the top, sometimes the items that were hidden re-appear unselected (DependencyProperty.UnsetValue).

I solved the issue by turning off the Row Virtualization (EnableRowVirtualization="False") but I would like to know if this is a bug or if I am missing a step when using custom datatemplates with virtualization.

I can submit a bug report with a demo of the problem if you prefer.

Thanks,
Jose

7 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 21 Oct 2010, 08:15 AM
Hi Jose Simas,

That could be a bug, so a sample project will help us to confirm it easily.

On the other hand, may I ask, why don't you use the built-in GridViewComboBoxColumn? You can check the online demo here.

Best wishes,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 21 Oct 2010, 11:24 AM
Hi,

Has it happens the error is mine. The line SelectedValue="{Binding SelectedItem}" is wrong, it should read SelectedValue="{Binding Value}" and in this case the Grid works fine with virtualization on. I am sorry for the confusion.

The reason I am not using the built-in GridViewComboBoxColumn is because you have to click three times for it to drop down the list of items: One to put the cell in edit mode, two to set the focus to the combobox and third: drop down the values. My requirement is for the dropdown to show its values with one click only so I had to resort to this custom grid column. Is there any way to have this behaviour with the built-in combo box column?

Regards,
Jose


0
Accepted
Yavor Georgiev
Telerik team
answered on 21 Oct 2010, 11:40 AM
Hi Jose Simas,

 You can very easily achieve your requirement - you need to set the EditTriggers property of RadGridView to CellClick and you need to set the OpenDropDownOnFocus property of the RadComboBox like so:
<telerik:GridViewComboBoxColumn ...>
  <telerik:GridViewComboBoxColumn.EditorStyle>
    <Style TargetType="telerik:RadComboBox">
      <Setter Property="OpenDropDownOnFocus" Value="True" />
    </Style>
  </telerik:GridViewComboBoxColumn.EditorStyle>
...
</telerik:GridViewComboBoxColumn>


Greetings,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 21 Oct 2010, 12:05 PM
Hi,

That is great thanks, it works just fine.

Jose
0
Jose Simas
Top achievements
Rank 2
answered on 21 Oct 2010, 12:20 PM
Hi,

Spoken a bit too soon :-)

It does work but I had to go back to my previous solution because the grid cell does not give any hint that that column is a combobox until you select it. The datatemplate solution shows the traditional combobox triangle that gives the clue to its existence. Since this is the only editable column in the grid then I need to show the clue that that column is selectable. Is this possible with the  GridViewComboBoxColumn? 

Thanks,
Jose
0
Accepted
Yavor Georgiev
Telerik team
answered on 21 Oct 2010, 12:26 PM
Hello Jose Simas,

 In this case, you can either keep to your current solution, or use a custom CellTemplate (not CellEditTemplate) to display a TextBlock with a small graphical hint. By default, when not in edit mode, the ComboBoxColumn displays its value in a TextBlock - the ComboBox is shown when entering edit mode.

Regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jose Simas
Top achievements
Rank 2
answered on 21 Oct 2010, 01:41 PM
Hi,

Good idea, I will do that. Many thanks for your timely answers and guidance!

Jose
Tags
GridView
Asked by
Jose Simas
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Jose Simas
Top achievements
Rank 2
Yavor Georgiev
Telerik team
Share this question
or