Represents the Xceed DataGrid for WPF control, which allows data to be displayed and edited, regardless of its layout.
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>