Xceed DataGrid for WPF v7.2 Documentation
DataGridControl Class
Members  Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace : DataGridControl Class
Represents the Xceed DataGrid for WPF control, which allows data to be displayed and edited, regardless of its layout.
Syntax
'Declaration
 
<TemplatePartAttribute(Name="PART_ScrollViewer", Type=System.Windows.Controls.ScrollViewer)>
<StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=Xceed.Wpf.DataGrid.DataRow)>
<DefaultEventAttribute("OnItemsChanged")>
<DefaultPropertyAttribute("Items")>
<ContentPropertyAttribute("Items")>
<LocalizabilityAttribute(LocalizationCategory.None, Readability=Readability.Unreadable)>
<XmlLangPropertyAttribute("Language")>
<UsableDuringInitializationAttribute(True)>
<RuntimeNamePropertyAttribute("Name")>
<UidPropertyAttribute("Uid")>
<TypeDescriptionProviderAttribute(MS.Internal.ComponentModel.DependencyObjectProvider)>
<NameScopePropertyAttribute("NameScope", System.Windows.NameScope)>
Public Class DataGridControl 
   Inherits System.Windows.Controls.ItemsControl
'Usage
 
Dim instance As DataGridControl
[TemplatePart(Name="PART_ScrollViewer", Type=System.Windows.Controls.ScrollViewer)]
[StyleTypedProperty(Property="ItemContainerStyle", StyleTargetType=Xceed.Wpf.DataGrid.DataRow)]
[DefaultEvent("OnItemsChanged")]
[DefaultProperty("Items")]
[ContentProperty("Items")]
[Localizability(LocalizationCategory.None, Readability=Readability.Unreadable)]
[XmlLangProperty("Language")]
[UsableDuringInitialization(true)]
[RuntimeNameProperty("Name")]
[UidProperty("Uid")]
[TypeDescriptionProvider(MS.Internal.ComponentModel.DependencyObjectProvider)]
[NameScopeProperty("NameScope", System.Windows.NameScope)]
public class DataGridControl : System.Windows.Controls.ItemsControl 
Remarks

By default, when a new DataGridControl instance is created, it will contain a GroupByControl and a ColumnManagerRow in its fixed headers.

Fixed Columns vs. Templates

In order to support fixed columns when creating a new row template for a table-view layout, the following criteria must be met:

  1. The PART_CellsHost template part must be a FixedCellPanel.
  2. The FixedCellCount property of the FixedCellPanel must be bound to the table view's FixedColumnCount property using a TwoWay ViewBinding.

The fixed-cell-panel properties listed below are also usually bound when provided a new row template for a table-view layout:

  1. SplitterStyle (TemplateBinding xcdg:TableView.FixedColumnSplitterStyle)
  2. SplitterWidth (xcdg:ViewBinding FixedColumnSplitterWidth)
  3. ShowSplitter (xcdg:ViewBinding ShowFixedColumnSplitter)
  4. FixedColumnDropMarkPen (xcdg:ViewBinding FixedColumnDropMarkPen)

If a new template is provided for a DataGridControl and fixed columns are to be supported, it is essential that a TableViewScrollViewer be used. This scroll viewer is responsible for preserving the TranslateTransforms that fix and scroll elements, as well as executing the PageLeft and PageRight actions according to the reduced viewport.  It is also recommended that an AdornerDecorator be located above the TableViewScrollViewer of the templated DataGridControl to support drag and dropping of the fixed-column splitter correctly.

Example
All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
This first code example demonstrates how to create a connection to the Access version of the Northwind database and create a property named Orders to which the grid will be bound. The code should be placed in the App.xaml.vb file.This first code example demonstrates how to create a connection to the Access version of the Northwind database and create a property named Orders to which the grid will be bound. The code should be placed in the App.xaml.cs file.The next example demonstrates how to bind a grid to the Orders table, which is retrieved through the Orders property implemented in the code above.The following example demonstrates how to bind a grid to an array defined in the resources of the containing grid.
Shared Sub New()

  Dim dataSet As New DataSet()
  Dim mdbfile As String = "Data\Northwind.mdb"
  Dim connString As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbfile)
  Dim conn As New OleDbConnection(connString)
  Dim adapter As New OleDbDataAdapter()

  m_adapter = New OleDbDataAdapter()
  m_adapter.SelectCommand = New OleDbCommand( "SELECT * FROM Employees;", conn )
  m_adapter.Fill( dataSet, "Employees" )
  m_employees = dataSet.Tables( "Employees" )
  m_adapter = New OleDbDataAdapter()
  m_adapter.SelectCommand = New OleDbCommand( "SELECT * FROM Orders;", conn )
  m_adapter.Fill( dataSet, "Orders" )
  m_orders = dataSet.Tables( "Orders" )
 
  m_adapter = New OleDbDataAdapter()
  m_adapter.SelectCommand = New OleDbCommand( "SELECT * FROM [Order Details];", conn )
  m_adapter.Fill( dataSet, "Order Details" )
  m_orderDetails = dataSet.Tables( "Order Details" ) 
  m_employees.ChildRelations.Add( New DataRelation( "Employee_Orders", m_employees.Columns( "EmployeeID" ), m_orders.Columns( "EmployeeID" ) ) )
  m_orders.ChildRelations.Add( New DataRelation( "Order_OrderDetails", m_orders.Columns( "OrderID" ), m_orderDetails.Columns( "OrderID" ) ) )
End Sub

Public Shared Readonly Property Employees As DataTable
  Get
    Return m_employees
   End Get
End Property

Public Shared Readonly Property Orders As DataTable
  Get
    Return m_orders
   End Get
End Property

Private Shared m_employees As DataTable
Private Shared m_orders As DataTable
Private Shared m_orderDetails As DataTable
Private Shared m_adapter As OleDbDataAdapter = Nothing
static App()
{

  DataSet dataSet = new DataSet();
  string mdbFile = @"Data\Northwind.mdb";
  string connString = String.Format( "Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile );

  OleDbConnection conn = new OleDbConnection( connString );

  m_adapter = new OleDbDataAdapter();
  m_adapter.SelectCommand = new OleDbCommand( "SELECT * FROM Employees;", conn );
  m_adapter.Fill( dataSet, "Employees" );
  m_employees = dataSet.Tables[ "Employees" ];
  m_adapter = new OleDbDataAdapter();
  m_adapter.SelectCommand = new OleDbCommand( "SELECT * FROM Orders;", conn )
  m_adapter.Fill( dataSet, "Orders" );
  m_orders = dataSet.Tables[ "Orders" ];
 
  m_adapter = new OleDbDataAdapter();
  m_adapter.SelectCommand = new OleDbCommand( "SELECT * FROM [Order Details];", conn );
  m_adapter.Fill( dataSet, "Order Details" );
  m_orderDetails = dataSet.Tables[ "Order Details" ];
  m_employees.ChildRelations.Add( new DataRelation( "Employee_Orders", m_employees.Columns[ "EmployeeID" ], m_orders.Columns[ "EmployeeID" ] ) );
  m_orders.ChildRelations.Add( new DataRelation( "Order_OrderDetails", m_orders.Columns[ "OrderID" ], m_orderDetails.Columns[ "OrderID" ] ) );  
}
public static DataTable Employees
{
  get
  {
    return m_employees;
   }
}

public static DataTable Orders
{
  get
  {
    return m_orders;
   }
}

private static DataTable m_employees;
private static DataTable m_orders;
private static DataTable m_orderDetails;
private static OleDbDataAdapter m_adapter = null;
<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}"/>
  </Grid.Resources>
  <xcdg:DataGridControl x:Name="OrdersGrid"
                        ItemsSource="{Binding Source={StaticResource cvs_orders}}"/>
</Grid>
<Grid xmlns:s="clr-namespace:System;assembly=mscorlib"
      xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">                     
  <Grid.Resources>
  <x:Array x:Key="data_list" Type="{x:Type s:String}">
    <s:String>Sunday</s:String>
    <s:String>Monday</s:String>
    <s:String>Tuesday</s:String>
    <s:String>Wednesday</s:String>
    <s:String>Thursday</s:String>
    <s:String>Friday</s:String>
    <s:String>Saturday</s:String>
  </x:Array>
  </Grid.Resources>
  <xcdg:DataGridControl x:Name="OrdersGrid"
                        ItemsSource="{StaticResource data_list}"/>
</Grid>
Inheritance Hierarchy

System.Object
   System.Windows.Threading.DispatcherObject
      System.Windows.DependencyObject
         System.Windows.Media.Visual
            System.Windows.UIElement
               System.Windows.FrameworkElement
                  System.Windows.Controls.Control
                     System.Windows.Controls.ItemsControl
                        Xceed.Wpf.DataGrid.DataGridControl

Requirements

See Also

Reference

DataGridControl Members
Xceed.Wpf.DataGrid Namespace

DataGrid Fundamentals

Providing Data
DataGridControl Class

Getting Started

Migrating from Xceed Grid for .NET