Skip to main content

Creating Your First Datagrid Project

The installer will copy all the necessary files into the product's installation folder (usually in [Installation Folder]\Xceed\Xceed DataGrid for WPF v[VERSION]) as well as place a copy of the Xceed DataGrid for WPF assemblies (Xceed.Wpf.DataGrid.dll) in the global assembly cache.

Adding the Component References to Visual Studio

In order to begin using Xceed DataGrid for WPF, its assemblies must be referenced in your project using the following steps:

  1. Select the "Add Reference..." option from the "Project" menu to open the "Add Reference" dialog box.

  2. Select the ".NET" tab, browse to the "Xceed DataGrid for WPF" assembly and select it. To use the Office 2007 themes, the corresponding assembly must also be included.

  3. Press "OK" to add the assemblies to your project's references.

Namespace Mapping

Once the assemblies have been added to your project, the namespace maps that are to be used must be declared. In XAML this is done using the xmlns attribute. If the DataGridControl control has been added to a design surface, the xmlns attribute is automatically added.

NamespaceDescription
Xceed.Wpf.DataGridThe Xceed.Wpf.DataGrid namespace regroups all the classes that are required by the DataGridControl class to edit and display data.
Xceed.Wpf.DataGrid.ConvertersThe Xceed.Wpf.DataGrid.Converters namespace regroups all the converter classes.
Xceed.Wpf.DataGrid.MarkupThe Xceed.Wpf.DataGrid.Markup namespace regroups the XAML-specific classes.
Xceed.Wpf.DataGrid.ValidationRulesThe Xceed.Wpf.DataGrid.ValidationRules namespace regroups all the validation rule classes.
Xceed.Wpf.DataGrid.ViewsThe Xceed.Wpf.DataGrid.Views namespace regroups all the classes which are required to apply views and themes to a DataGridControl.
Xceed.Wpf.DataGrid.SettingsThe Xceed.Wpf.DataGrid.Settings namespace regroups all the classes, enumerations, and structures required to persist the settings of a grid and its elements.
Xceed.Wpf.DataGrid.AutomationThe Xceed.Wpf.DataGrid.Automation namespace contains all the classes that are required to support UI automation.

In C# or VB.NET, the using and Imports directives can be used to create aliases for the namespaces listed in Table 1. If Xceed DataGrid for WPF is being used in either of these development languages the Xceed.Wpf.DataGrid.Markup namespace can be omitted as it contains XAML-specific classes.

  using Xceed.Wpf.DataGrid;
using Xceed.Wpf.DataGrid.Converters;
using Xceed.Wpf.DataGrid.ValidationRules;
using Xceed.Wpf.DataGrid.Views;
using Xceed.Wpf.DataGrid.Settings;

Binding

The last step is to add a grid to your page or window. The examples found throughout the documentation usually place the grid inside a Grid, as demonstrated in the following example.

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.

  public partial class App : Application
{
public DataSet Data
{
get; set;
}
public DataTable Orders
{
get; set;
}
protected override void OnStartup( StartupEventArgs e )
{
// Set the licence key
Xceed.Wpf.DataGrid.Licenser.LicenseKey = "Enter your license key here";
Data = Xceed.Wpf.DataGrid.Samples.SampleData.DataProvider.GetNorthwindDataSet();
Orders = Data.Tables[ "Orders" ];
base.OnStartup( e );
}
}

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.

  <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>