Xceed DataGrid for WPF v7.3 Documentation
Xceed.Wpf.DataGrid Assembly / Xceed.Wpf.DataGrid Namespace / DataGridContext Class / GetItemFromContainer Method
A DependencyObject representing the container of an item in the context.
Example


    GetItemFromContainer Method (DataGridContext)
    Retrieves an item for the specified container.
    Syntax
    'Declaration
     
    Public Function GetItemFromContainer( _
       ByVal container As DependencyObject _
    ) As Object
     
    'Usage
     
    Dim instance As DataGridContext
    Dim container As DependencyObject
    Dim value As Object
     
    value = instance.GetItemFromContainer(container)

    Parameters

    container
    A DependencyObject representing the container of an item in the context.

    Return Value

    The item for the specified container.
    Example
    All examples in this topic assume that the grid is bound to the Orders or Employees table of the Northwind database, unless stated otherwise.
    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.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.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.
    <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>
        <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>
    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