DataGridControl Class
See Also  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.

Object Model












Syntax

Visual Basic (Declaration) 
<StyleTypedPropertyAttribute(Property="CellErrorStyle", StyleTargetType=Xceed.Wpf.DataGrid.Cell)>
<TemplatePartAttribute(Name="PART_ScrollViewer", Type=System.Windows.Controls.ScrollViewer)>
Public Class DataGridControl 
   Inherits ItemsControl
   Implements IGeneratorHost, INotifyPropertyChangedISupportInitializeIDocumentPaginatorSourceIFrameworkInputElementIInputElementIAddChildIHaveResourcesIAnimatableDUCE.IResource 
C# 
[StyleTypedPropertyAttribute(Property="CellErrorStyle", StyleTargetType=Xceed.Wpf.DataGrid.Cell)]
[TemplatePartAttribute(Name="PART_ScrollViewer", Type=System.Windows.Controls.ScrollViewer)]
public class DataGridControl : ItemsControl, IGeneratorHost, INotifyPropertyChangedISupportInitializeIDocumentPaginatorSourceIFrameworkInputElementIInputElementIAddChildIHaveResourcesIAnimatableDUCE.IResource  

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.
Visual BasicCopy Code
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
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.
C#Copy Code
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;
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.
XAMLCopy Code
<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> 
The following example demonstrates how to bind a grid to an array defined in the resources of the containing grid.
XAMLCopy Code
<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>

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 This feature is available only in the Professional Edition

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.

Notes

By default, a grid will take all the room that it requires; therefore, if it is not given a size constraint, such as when it is placed in a StackPanel, and a large amount of data items are present, UI virtualization will be lost—resulting in a significant loss in performance. To preserve UI virtualization when a grid is in a StackPanel, the MaxWidth and MaxHeight properties (or Width and Height) must be used to constrain it. As an alternative, a DockPanel or Grid can be used as both impose size constraints on their child elements.

The ItemContainerGenerator property is obsolete and has been replaced by the GetContainerFromItem and GetItemFromContainer methods.

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

Supported Operating Systems: Windows Server 2003 Service Pack 1; Windows Vista; Windows XP Service Pack 2

See Also