| Visual Basic (Declaration) | |
|---|---|
<StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=Xceed.Wpf.DataGrid.DataRow)> <StyleTypedPropertyAttribute(Property="CellErrorStyle", StyleTargetType=Xceed.Wpf.DataGrid.Cell)> <TemplatePartAttribute(Name="PART_ScrollViewer", Type=System.Windows.Controls.ScrollViewer)> Public Class DataGridControl Inherits System.Windows.Controls.ItemsControl | |
| Visual Basic (Usage) | Copy Code |
|---|---|
Dim instance As DataGridControl | |
| C# | |
|---|---|
[StyleTypedPropertyAttribute(Property="ItemContainerStyle", StyleTargetType=Xceed.Wpf.DataGrid.DataRow)] [StyleTypedPropertyAttribute(Property="CellErrorStyle", StyleTargetType=Xceed.Wpf.DataGrid.Cell)] [TemplatePartAttribute(Name="PART_ScrollViewer", Type=System.Windows.Controls.ScrollViewer)] public class DataGridControl : System.Windows.Controls.ItemsControl | |
| Visual Basic | Copy 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 | |
| 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; | |
| XAML | Copy 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> | |
| XAML | Copy 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> | |
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:
- The PART_CellsHost template part must be a FixedCellPanel.
- 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:
- SplitterStyle (TemplateBinding xcdg:TableView.FixedColumnSplitterStyle)
- SplitterWidth (xcdg:ViewBinding FixedColumnSplitterWidth)
- ShowSplitter (xcdg:ViewBinding ShowFixedColumnSplitter)
- 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.
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.
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
Target Platforms: Windows 2000, Windows XP SP3 Family, Windows Server 2003-2008 Family, Windows Vista, Windows 7
Reference
DataGridControl MembersXceed.Wpf.DataGrid Namespace
DataGrid Fundamentals
Providing DataDataGridControl Class
Copy Code