Home Forums WinForms controls Xceed Grid for WinForms Programmatically toggling group expansion

Viewing 1 post (of 1 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #17800 |

    The following example demonstrates how to handle the PreviewMouseLeftButtonDown event on the GroupHeaderControl objects contained in the headers of the child groups to toggle the expansion state of child groups using the ToggleGroupExpansion method. The group whose state is to be toggled will be retrieved using the GetParentGroupFromItem method.

    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid”&gt;
      <Grid.Resources>
        <xcdg:DataGridCollectionViewSource x:Key=”cvs_orders”
                                           Source=”{Binding Source={x:Static Application.Current},
                                                            Path=Orders}”>

          <xcdg:DataGridCollectionViewSource.GroupDescriptions>
            <xcdg:DataGridGroupDescription PropertyName=”ShipCountry”/>
            <xcdg:DataGridGroupDescription PropertyName=”ShipCity”/>
          </xcdg:DataGridCollectionViewSource.GroupDescriptions>
        </xcdg:DataGridCollectionViewSource>

        <Style TargetType=”{x:Type xcdg:GroupHeaderControl}”>
          <EventSetter Event=”PreviewMouseLeftButtonDown”
                       Handler=”HeaderDown”/>
        </Style>  
      </Grid.Resources>

      <xcdg:DataGridControl x:Name=”OrdersGrid”
                            ItemsSource=”{Binding Source={StaticResource cvs_orders}}”/>
    </Grid>

    The following code provides the implementation of the PreviewMouseLeftButtonDown event in which we will retrieve the item represented by the GroupHeaderControl (GroupHeaderFooterItem) using the GetItemFromContainer method, which will then be used to retrieve the parent group (GetParentGroupFromItem) whose state is to be toggled.

    VB.NET

    Private Sub HeaderDown( ByVal sender As Object, ByVal e As MouseButtonEventArgs )
      Dim headerControl As GroupHeaderControl = TryCast( sender, GroupHeaderControl );
      If headerControl Is Nothing Then
        Return
      End If

      Dim context As DataGridContext = DataGridControl.GetDataGridContext( headerControl )
      Dim item As Object = context.GetItemFromContainer( headerControl ) )

      If Not item Is Nothing Then
        Dim group As CollectionViewGroup = context.GetParentGroupFromItem( item )
        If Not group Is Nothing
          context.ToggleGroupExpansion( group )
        End If
      End If
    End Sub

    C#

    Imported from legacy forums. Posted by Xceed admin (had 787 views)

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.