How can I make the GroupHeaderRow and/or the GroupFooterRow selectable?

4 posts, 0 answers
  1. Ryan
    Ryan avatar
    4 posts
    Member since:
    Nov 2014

    Posted 19 Mar 2015 Link to this post

    I have created a simple grid that has group header rows following the Aggregates example.

    <Style TargetType="telerik:GroupHeaderRow">               
      <
    Setter Property="ShowGroupHeaderColumnAggregates" Value="True" />               
      <
    Setter Property="ShowHeaderAggregates" Value="False" />           
    </
    Style>

    Now the issue I have is that I want my users to be able to select the cells in this grid and paste them into Excel.  The issue is that I can select, copy and paste the regular data rows fine but I can't select the cells with the aggregate data.  Is there a way to make the aggregate rows selectable?


  2. Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 21 Mar 2015 Link to this post

    Hello Ryan,

    This functionality is not supported out-of-the-box by RadGridView.

    As a workaround I can suggest you implementing a custom copying behavior. A possible way of achieving this is to subscribe to the Copying event of RadGridView and add your own copying logic within the event handler. The following code snippet illustrates how the AggregateResult for each group can be obtained, as described in the Get aggregates from a group article:​
    private void clubsGrid_Copying(object sender, GridViewClipboardEventArgs e)
    {
        foreach (QueryableCollectionViewGroup item in this.clubsGrid.Items.Groups)
        {
            string value = item.AggregateResults[0].FormattedValue.ToString();
        }
    }

    You can check the Copying documentation article for more information on the available copying events of RadGridView.

    You can also refer also to the Copy paste functionality example using the SDK Sample Browser, as well as to the Add Data to the Clipboard and Retrieve Data from the Clipboard articles.

    I hope that this helps.

    Best Regards,
    Stefan
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Ryan
    Ryan avatar
    4 posts
    Member since:
    Nov 2014

    Posted 22 Mar 2015 in reply to Stefan Link to this post

    Thanks for the suggestion but unfortunately this does not really work from a usability perspective.  Sometimes the user might want to select just the aggregate numbers, sometimes they don't want the aggregates at all and just some rows.  Since these aggregates aren't selectable I have no idea if the user wants to copy them or not.  I know I could add some extra controls to allow the user to specify whether they want the aggregates or not but I think this would get in the way of a simple experience of just being able to copy whatever cells you see on the grid.

    I also am unable to select the aggregates in the ColumnFooter as well.  I am assuming that the same issue applies to the column footer as well?

    Thanks

  4. Stefan
    Admin
    Stefan avatar
    1073 posts

    Posted 24 Mar 2015 Link to this post

    Hi Ryan,

    I can suggest you the following steps as a workaround or this case:

    1.   Predefine the TextBox ContentTemplate and use it  in the column footer as its content can be selected:
    <ControlTemplate x:Key="temp"  TargetType="TextBox">
        <ScrollViewer  x:Name="PART_ContentHost"
                        Padding="{TemplateBinding Padding}"
                        Foreground="{TemplateBinding Foreground}" Background="Transparent"
                        VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                        HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"/>
    </ControlTemplate>

    2.   Apply the predefined ContentTemplate to the TextBox within the column footer:
    <telerik:GridViewDataColumn.Footer>
        <telerik:AggregateResultsList ItemsSource="{Binding}"
                                      VerticalAlignment="Center">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal"
                                VerticalAlignment="Center">
                        <TextBox  VerticalAlignment="Stretch"
                                  SelectionBrush="Gray"
                                  Text="{Binding Caption, Mode=OneWay}"
                                  Style="{StaticResource ss}"/>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Vertical" />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
        </telerik:AggregateResultsList>
    </telerik:GridViewDataColumn.Footer>

    I hope that this helps.

    Best Regards,
    Stefan
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top