Xceed DataGrid for WPF v7.3 Documentation
Xceed.Wpf.DataGrid Assembly / Xceed.Wpf.DataGrid Namespace / DataGridControl Class / CurrentContext Property
Example


In This Topic
    CurrentContext Property
    In This Topic
    Gets the context in which the global current item is located.
    Syntax
    'Declaration
     
    Public ReadOnly Property CurrentContext As DataGridContext
    'Usage
     
    Dim instance As DataGridControl
    Dim value As DataGridContext
     
    value = instance.CurrentContext
    public DataGridContext CurrentContext {get;}

    Property Value

    A DataGridContext representing the context in which the global current item is located.
    Example
    All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
    The following example demonstrates how to retrieve the parent group of the current item using the GetParentGroupFromItem method so that it can be collapsed. The implementation for the CollapseCurrentGroup method is provided below.The following provides the implementation for the CollapseCurrentGroup method.The following provides the implementation for the CollapseCurrentGroup method.
    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
      <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>
      </Grid.Resources>
      <DockPanel>
    
        <Button Content="Collapse Group"
                 Click="CollapseCurrentGroup"
                DockPanel.Dock="Top"/>
        <xcdg:DataGridControl x:Name="OrdersGrid"
                              ItemsSource="{Binding Source={StaticResource cvs_orders}}"
                              DockPanel.Dock="Bottom"/>
      </DockPanel>
    </Grid>
    Private Sub CollapseCurrentGroup( ByVal sender As Object, ByVal e As RoutedEventArgs )
    
      Dim context As DataGridContext = Me.OrdersGrid.CurrentContext
    
      Dim group As CollectionViewGroup = context.GetParentGroupFromItem( context.CurrentItem )
      context.CollapseGroup( group )
    End Sub
    private void CollapseCurrentGroup( object sender, RoutedEventArgs e )
    {
    
      DataGridContext context = this.OrdersGrid.CurrentContext;
      CollectionViewGroup group = context.GetParentGroupFromItem( context.CurrentItem );
      context.CollapseGroup( group );
    }
    Requirements

    Target Platforms: Windows 11, Windows, 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also