View previous topic :: View next topic |
Author |
Message |
jorgen
Joined: 06 Dec 2011 Posts: 6
|
Posted: Wed Dec 07, 2011 5:34 pm Post subject: Binding to xml |
|
|
Hi,
I have a very simple xml with parent child relations which I load into a dataset by using ReadXml. How can I load this into the virtualtree? (Artikler is the root node and then the others are connected) This is a sample of the xml:
<xml>
<Equipment>
<Code>Artikler</Code><Name>ARTIKLER</Name><Parent>NULL</Parent>
<Code>M00</Code><Name>DIV ARTIKLER</Name><Parent>Artikler</Parent>
<Code>M23</Code><Name>DELER F/DRAG-, BREMSE-, OG FJÆRSTELL</Name><Parent>Artikler</Parent>
<Code>M26</Code><Name>DIV ARTIKLER TRYKKLUFT</Name><Parent>Artikler</Parent>
<Code>M62</Code><Name>BOGGIER F/PERSONVOGNER</Name><Parent>Artikler</Parent>
<Code>S01</Code><Name>KASSE</Name><Parent>Artikler</Parent>
<Code>S02</Code><Name>LØPEVERK</Name><Parent>Artikler</Parent>
<Code>S03</Code><Name>BREMSER</Name><Parent>Artikler</Parent>
<Code>S04</Code><Name>TRYKKLUFT</Name><Parent>Artikler</Parent>
<Code>S05</Code><Name>EL-FORSYNING</Name><Parent>Artikler</Parent>
</Equipment>
Best regards
Jørgen |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Dec 07, 2011 7:43 pm Post subject: |
|
|
If you are loading the data into a DataSet then you can bind to the DataSet using DataSet binding. See the help section on Data Set binding and the sample project which illustrates DataSet binding. _________________ Infralution Support |
|
Back to top |
|
|
jorgen
Joined: 06 Dec 2011 Posts: 6
|
Posted: Thu Dec 08, 2011 8:33 am Post subject: |
|
|
Thanks for your quick reply. However I am still not able to bind to the xml loaded into the dataset. I just want to show the names in the xml in a hierarchy where the Parent points to the Code for each row. I have tried both using the wizard and doing this programmatically, but it is not clear to me from the help file how I should do this. Can you give me a more detailed explanation?
Best regards
Jørgen |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Dec 09, 2011 5:01 am Post subject: |
|
|
Is the problem that you cannot display the data from the Dataset at all - or that it is not in the form/hierarchy you want. If it is the latter then perhaps you may need to use programmatic or object binding (there are sample projects and help for this). In this case you would define a class/objects to represent your data and read the XML into this structure (.NET supports XML streaming into objects). Then you can bind Virtual Tree to the properties of these objects. _________________ Infralution Support |
|
Back to top |
|
|
jorgen
Joined: 06 Dec 2011 Posts: 6
|
Posted: Fri Dec 09, 2011 8:09 am Post subject: |
|
|
My problem is that nothing shows up in the treeview.
I realise I could bind to an object but I was hoping to be able to bind directly to the xml which I load into a dataset. Each row in the xml contains a code, name and parent. The parent for the top node is null and the other parents points to the code for the above level. Here is a sample:
<Codes>
<Equipment>
<EqCode>Artikler</EqCode><EqName>ARTIKLER</EqName><EqParent>NULL</EqParent>
</Equipment>
<Equipment>
<EqCode>M00</EqCode><EqName>DIV ARTIKLER</EqName><EqParent>Artikler</EqParent>
</Equipment>
<Equipment>
<EqCode>M23</EqCode><EqName>DELER F/DRAG-, BREMSE-, OG FJÆRSTELL</EqName><EqParent>Artikler</EqParent>
</Equipment>
<Equipment>
<EqCode>M26</EqCode><EqName>DIV ARTIKLER TRYKKLUFT</EqName><EqParent>Artikler</EqParent>
</Equipment>
</Codes>
Then I do the following in an attempt to bind programmatically directly to the dataset:
DataSet objDataSet = new DataSet();
objDataSet.ReadXml(@"C:\XMLFile1.xml");
virtualTree1.DataSource = objDataSet;
DataViewRowBinding viewBinding = new DataViewRowBinding();
virtualTree1.RowBindings.Add(viewBinding);
DataRowRowBinding eqRowBinding = new DataRowRowBinding();
eqRowBinding.Table = "Equipment";
virtualTree1.RowBindings.Add(eqRowBinding);
...
From then on I can only guess how to set up the cell bindings and parentrelations.... Maybe it is not possible to do it this way?
We have other projects where object binding and database connections is the natural choice, and your help files and sample projects show details of this, however, I was also hoping to use it as shown above binding directly to an xml loaded into a dataset.
Best regards
Jørgen Stang |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Dec 09, 2011 7:28 pm Post subject: |
|
|
There are several possible issues with your code. The first is that every tree requires (at least) one column (to display data in). If you don't have that then you will get a completely empty tree. The next issue is that you need to add CellBindings for each RowBinding that map data from your data source to each of the columns in the tree. Finally you have set the DataSource to the DataSet where as you need to set it to a table within the DataSet.
It is much easier to create columns and bindings using the VirtualTree designer (right click and select "Edit Virtual Tree". You can create your bindings using the designer and then select the DataSource programatically as you have done. If you really want to create the bindings programatically you can - just take a look at the designer generated code (in the MyForm.designer.cs file) and use it as a guide. _________________ Infralution Support |
|
Back to top |
|
|
jorgen
Joined: 06 Dec 2011 Posts: 6
|
Posted: Tue Dec 13, 2011 2:09 pm Post subject: |
|
|
ok, thanks, so now I got further and get all my records (rows) listed sequentially in the treeview, but the parent child relations are not set. The rows are nested in the xml by EqParent pointing to EqCode and I am not sure how to configure this in the treeview. I have tried a lot of options like setting ParentRelation to EqParent and ChildRelation to EqCode, but this does not produce the hierarchy.
Currently I have one column configured (EqColumn) and 2 databindings: DataRow(Equipment) and DataView(Equipment) with EqName connected to the databindings.
Any suggestions to how I set up the parent-child relations correctly? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Dec 14, 2011 2:41 am Post subject: |
|
|
Because your data has (I think) recursive parent child relations you don't actually want to display the entire table. See the following thread on binding to recursive data:
http://www.infralution.com/phpBB2/viewtopic.php?t=1772 _________________ Infralution Support |
|
Back to top |
|
|
jorgen
Joined: 06 Dec 2011 Posts: 6
|
Posted: Wed Dec 14, 2011 8:56 pm Post subject: |
|
|
The recursive databinding example is using DataView and RowFilter which I can not find in the proprtypages for the virtualtree.
Is it possible for you to create a recursive databinding sample identical to the one you have, just replacing the access file with an xml file and post it somewhere? There are lots of parameters to set in your tool, and my evaluation period is running out... |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Wed Dec 14, 2011 10:01 pm Post subject: |
|
|
DataView and RowFilter are both properties of the DataSet (not VirtualTree) so if you have loaded your XML into a DataSet the code should be similar - since in the sample code Virtual Tree is binding to the DataSet (the Access database is just used to load the DataSet).
If you can email a zipped copy of your project (or a cut down version of it)to support@infralution.com we will take a look and help you configure Virtual Tree. _________________ Infralution Support |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Sun Dec 18, 2011 10:42 pm Post subject: |
|
|
Thanks for the zipped project. I have emailed you a reply with a working version of the project. _________________ Infralution Support |
|
Back to top |
|
|
|