$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
DataGridView WinForms Component
Hierarchical data binding of GridView C#.NET control in Windows Forms applications
Home > WinForms UI Controls > User Manual > XML Data Source for Grid in C#

Bind GridView to Hierarchical with XML Data Source

The Kettic DataGridView Control does not support the data binding to XML directly, but accomplish data binding to XML through DataTables. Users of the Kettic DataGridView component are able to create DataSet and DataTables from an XML document. The following is a XML file used in data binding for GridView control. The Kettic DataGridView is not capable of many-to-many relations, which may be included in the DataTables created by XML files.

Create Hierarchy with XML Data Source

To bind GridView component to XML, we need to create a DataSet instance from the xml file first. In the example of binding GridView to XML, there is only a single DataTable which is set as the data source of Kettic GridView control. It is also possible to bind GridView to hierarchy data of XML file, which is available on binding to hierarchy data. The following is the XML file that will be used in binding to hierarchy data.

<?xml version="1.0" encoding="utf-8"?>
<Orders>
<Order>
<OrderNumber>1597534</OrderNumber>
<WarehouseNumber>CA</WarehouseNumber>
<CreateDate>08/25/2012 15:30:12</CreateDate>
<Products>
<Product>
<ProductNumber>A001</ProductNumber>
<ProductDescription>Product available</ProductDescription>
<ProductPrice>19.99</ProductPrice>
</Product>
<Product>
<ProductNumber>A002</ProductNumber>
<ProductDescription>No Product available</ProductDescription>
<ProductPrice>39.98</ProductPrice>
</Product>
<Product>
<ProductNumber>A003</ProductNumber>
<ProductDescription>Product available</ProductDescription>
<ProductPrice>36.00</ProductPrice>
</Product>
<Product>
<ProductNumber>A004</ProductNumber>
<ProductDescription>No Product available</ProductDescription>
<ProductPrice>199.00</ProductPrice>
</Product>
<Product>
<ProductNumber>A005</ProductNumber>
<ProductDescription>Product available</ProductDescription>
<ProductPrice>598.00</ProductPrice>
</Product>
<Product>
<ProductNumber>A006</ProductNumber>
<ProductDescription>No Product available</ProductDescription>
<ProductPrice>798.99</ProductPrice>
</Product>
<Product>
<ProductNumber>A007</ProductNumber>
<ProductDescription>Product available</ProductDescription>
<ProductPrice>998.00</ProductPrice>
</Product>
<Product>
<ProductNumber>A008</ProductNumber>
<ProductDescription>No Product available</ProductDescription>
<ProductPrice>720.88</ProductPrice>
</Product>
<Product>
<ProductNumber>A009</ProductNumber>
<ProductDescription>Product available</ProductDescription>
<ProductPrice>369.59</ProductPrice>
</Product>
<Product>
<ProductNumber>A010</ProductNumber>
<ProductDescription>No Product available</ProductDescription>
<ProductPrice>490.40</ProductPrice>
</Product>
</Products>
</Order>
<Order>
<OrderNumber>0000</OrderNumber>
<WarehouseNumber>JAK</WarehouseNumber>
<CreateDate>03/05/2012 12:35:00</CreateDate>
<Products>
<Product>
<ProductNumber>003</ProductNumber>
<ProductDescription>Product not available</ProductDescription>
<ProductPrice>42.99</ProductPrice>
</Product>
<Product>
<ProductNumber>004</ProductNumber>
<ProductDescription>4 Product available</ProductDescription>
<ProductPrice>100.00</ProductPrice>
</Product>
</Products>
</Order>
</Orders>
And now, we can use the xml file to create hierarchical data binding for Kettic GridView. In the DataSet we created above, there are three tables in the XML file, however, users can ignore the second one and use the first and third ones only. The ReadXml method will automatically add the Order_Id and Product_Id columns to the created tables. The following is the C# code demonstrating the process of creating hierarchical binding to XML data for GridView control.

void CreateHierarchyUsingXmlDataSource_Load(object sender, EventArgs e)
{
DataSet xmlDataSet = new DataSet();
xmlDataSet.ReadXml("..\\KetticGridView\\DataGrid\\hierarchicalGridXml.xml");
GridViewTemplate productsTemplate = new GridViewTemplate();
this.ketticGridView1.MasterTemplate.Templates.Add(productsTemplate);
GridViewRelation relation = new GridViewRelation(this.ketticGridView1.MasterTemplate);
relation.ChildTemplate = productsTemplate;
relation.RelationName = " Order_ products";
relation.ParentColumnNames.Add("Order_Id");
relation.ChildColumnNames.Add("Products_Id");
ketticGridView1.Relations.Add(relation);
this.ketticGridView1.DataSource = xmlDataSet.Tables[0];
partsTemplate.DataSource = xmlDataSet.Tables[2];
this.ketticGridView1.MasterTemplate.BestFitColumns();
this.ketticGridView1.MasterTemplate.Templates[0].BestFitColumns();
}
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls