This is a migrated thread and some comments may be shown as answers.

Can I display the Hierarchical view like following XML file?

1 Answer 40 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Z
Top achievements
Rank 1
Z asked on 06 Mar 2009, 05:25 PM
<?xml version="1.0" encoding="utf-8"?>  
<Invoices> 
<Invoice> 
  <InvoiceNumber>456789</InvoiceNumber> 
  <JobNumber>TTT</JobNumber> 
  <CreateDate>01/03/2009 12:23:34</CreateDate> 
  <Parts> 
       <Part> 
           <PartNumber>001</PartNumber> 
           <PartDescription>Part Number 1 has expection</PartDescription> 
           <PartPrice>12.99</PartPrice> 
 
       </Part> 
       <Part> 
           <PartNumber>002</PartNumber> 
           <PartDescription>No Part available</PartDescription> 
           <PartPrice>60.00</PartPrice> 
       </Part> 
  </Parts> 
 
          
</Invoice> 
<Invoice> 
  <InvoiceNumber>0000</InvoiceNumber> 
  <JobNumber>SSSS</JobNumber> 
  <CreateDate>01/01/2001 11:00:00</CreateDate> 
  <Parts> 
       <Part> 
           <PartNumber>003</PartNumber> 
           <PartDescription>Part Number3 has expection</PartDescription> 
           <PartPrice>42.99</PartPrice> 
 
       </Part> 
       <Part> 
           <PartNumber>004</PartNumber> 
           <PartDescription>4 Part available</PartDescription> 
           <PartPrice>100.00</PartPrice> 
       </Part> 
  </Parts> 
 
          
</Invoice> 
</Invoices> 
the Invoice table to part table is many to many
so  table diagram is  "Invioce" -> "InvoiceParts" ->"Parts"
any sample codes how to implement it?

here is my source code
 Dim mO As New XMLOperater  
        grdvewCurrentParts.DataSource = mO.XMLToDataSet("C:\xmlfile.xml").Tables(0)  
        Dim template As Telerik.WinControls.UI.GridViewTemplate = New Telerik.WinControls.UI.GridViewTemplate  
        template.DataSource = mO.XMLToDataSet("C:\xmlfile.xml").Tables(1)  
 grdvewCurrentParts.MasterGridViewTemplate.ChildGridViewTemplates.Add(template)  
        Dim template2 As Telerik.WinControls.UI.GridViewTemplate = New Telerik.WinControls.UI.GridViewTemplate  
        template2.DataSource = mO.XMLToDataSet("C:\xmlfile.xml").Tables(2)  
        template.ChildGridViewTemplates.Add(template2)  
 
 
        grdvewCurrentParts.MasterGridViewTemplate.ChildGridViewTemplates.Add(template2)  
 
        Dim relation As GridViewRelation = New GridViewRelation(grdvewCurrentParts.MasterGridViewTemplate)  
        Dim relation2 As GridViewRelation = New GridViewRelation(grdvewCurrentParts.MasterGridViewTemplate.ChildGridViewTemplates(template))  
        relation.ChildTemplate = template  
        relation2.ChildTemplate = template2  
        relation.ParentColumnNames.Add("Invoice_Id")  
        relation.ChildColumnNames.Add("Invoice_Id")               relation2.ParentColumnNames.Add("Parts_Id")  
        relation2.ChildColumnNames.Add("Parts_Id")  
        grdvewCurrentParts.Relations.Add(relation)  
 
grdvewCurrentParts.Relations.Add(relation2)  
 
thank you very much!

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 10 Mar 2009, 09:35 PM
Hi Z,

Thank you for contacting us.

We do not support many-to-many relations, but just one-to-many and one-to-one. Since your xml data is one-to-many, it therefore can be presented. You have essentially used an elimination. Please refer to this external resource.

The DataSet created by ReadXml method contains 3 tables which you can avoid easily by skipping the second table and using the first and the third ones only. Here is sample code for your xml:

 private void Form1_Load(object sender, EventArgs e) 
        { 
             
             
            
            DataSet xmlDataSet = new DataSet(); 
            xmlDataSet.ReadXml("myXML.xml"); 
             
 
            GridViewTemplate partsTemplate = new GridViewTemplate(); 
            this.radGridView1.MasterGridViewTemplate.ChildGridViewTemplates.Add(partsTemplate); 
            GridViewRelation relation = new GridViewRelation(this.radGridView1.MasterGridViewTemplate); 
            relation.ChildTemplate = partsTemplate; 
            relation.RelationName = "Invoices_Parts"
            relation.ParentColumnNames.Add("Invoice_Id"); 
            relation.ChildColumnNames.Add("Parts_Id"); 
            radGridView1.Relations.Add(relation); 
            this.radGridView1.DataSource = xmlDataSet.Tables[0]; 
            partsTemplate.DataSource = xmlDataSet.Tables[2]; 
             
            
        } 

The Invoice_Id and Parts_Id columns were added automatically to the tables by ReadXml method. I checked what was created and set all the parameters respectively in the Form_Load event handler.

I will update our documentation with topics about loading xml. Do not hesitate to write me back if you have further questions.

 
Regards,
Nick
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Z
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or