View previous topic :: View next topic |
Author |
Message |
Robertico
Joined: 12 Apr 2010 Posts: 7
|
Posted: Mon Apr 12, 2010 5:21 pm Post subject: Bind hierarchical XML like 'ADO.NET Dataset Browser' example |
|
|
Is it possible to parse a hierarchical XML file and bind it to Virtual Tree, like the 'ADO.NET Dataset Browser' example.
Sample code is appreciated - (VS2008 - C#) |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Apr 12, 2010 11:30 pm Post subject: |
|
|
Yes - ADO.NET Datasets support reading data from hierarchical XML. So you can simply read the data into a dataset and then bind to the dataset. See this MSDN article on reading XML data into Datasets:
http://msdn.microsoft.com/en-us/library/fx29c3yd(VS.71).aspx
If you create a Dataset upfront using the dataset designer that matches your XML schema then you can bind to the dataset at design time (just like the ADO.NET Dataset Browser sample). If you use the DataSet.ReadXml methods ability to dynamically create the Dataset (based on an inferred schema) then you will need to create the Virtual Tree bindings at runtime. _________________ Infralution Support |
|
Back to top |
|
|
Robertico
Joined: 12 Apr 2010 Posts: 7
|
Posted: Tue Apr 13, 2010 4:02 pm Post subject: |
|
|
Thanks for the explanation. I'm going to try. _________________ There are only 10 types of people in the world: Those who understand binary, and those who don't |
|
Back to top |
|
|
Robertico
Joined: 12 Apr 2010 Posts: 7
|
Posted: Fri Apr 16, 2010 7:25 am Post subject: |
|
|
I use the DataSet.ReadXml methods ability. I do not understand how create the Virtual Tree bindings at runtime. _________________ There are only 10 types of people in the world: Those who understand binary, and those who don't |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Apr 16, 2010 8:11 am Post subject: |
|
|
Actually if your schema is fixed (ie you know what the table and column names will be) then you can just create the bindings in the designer as described in the help section "Data Binding to ADO.NET Datasets and DataViews".
If you do want or need to create the bindings programmatically then you need to do something like the following example which would bind Virtual Tree to the customer table in the DataSet sample project:
Code: | // add a binding for the root item (the DataView/Table)
//
DataViewRowBinding viewBinding = new DataViewRowBinding();
_virtualTree.RowBindings.Add(viewBinding);
// add a binding for rows from the table
//
DataRowRowBinding customerRowBinding = new DataRowRowBinding();
customerRowBinding.Table = "Customers";
customerRowBinding.Icon = Properties.Resources.CustomerIcon;
_virtualTree.RowBindings.Add(customerRowBinding);
// add cell bindings that bind fields from the row to particular Virtual Tree columns
//
customerRowBinding.CellBindings.Add(new DataRowCellBinding(colMain, "CompanyName"));
customerRowBinding.CellBindings.Add(new DataRowCellBinding(colAddress, "Address")); |
_________________ Infralution Support |
|
Back to top |
|
|
Robertico
Joined: 12 Apr 2010 Posts: 7
|
Posted: Sat Apr 17, 2010 11:31 am Post subject: |
|
|
It worked.
Many thanks ! _________________ There are only 10 types of people in the world: Those who understand binary, and those who don't |
|
Back to top |
|
|
|