How to deal with GridViewDataColumn.CellTemplate and virtualization

8 posts, 2 answers
  1. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 20 Oct 2010 Link to this post

    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
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 Oct 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 21 Oct 2010 Link to this post

    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


  5. Answer
    Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Oct 2010 Link to this post

    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
  6. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 21 Oct 2010 Link to this post

    Hi,

    That is great thanks, it works just fine.

    Jose
  7. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 21 Oct 2010 Link to this post

    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
  8. Answer
    Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Oct 2010 Link to this post

    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
  9. Jose Simas
    Jose Simas avatar
    35 posts
    Member since:
    Mar 2009

    Posted 21 Oct 2010 Link to this post

    Hi,

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

    Jose
Back to Top
UI for WPF is Visual Studio 2017 Ready