Populate radGrid with Hierarchical XML Data

4 posts, 1 answers
  1. Doug
    Doug avatar
    26 posts
    Member since:
    Feb 2011

    Posted 18 Jul 2011 Link to this post

    I have been trying to follow the code for loading data into a radgrid using an xml file with hierarchical data with no luck.  I have a similar file to the sample invoices / parts code located throughout the telerik codes samples and I can't get "table[0]" to bind with table[2].  The one thing I don't see in any of the samples is the properties that need to be set on the grid after in is placed on a winform (not sure if this is really the problem.  Below is the code for my function:

    private void uiTSSearchTitleScan_Click(object sender, EventArgs e)
    {
        DAOLoginService.DAOLoginService LoginServices = new DAOLoginService.DAOLoginService();
        DAODataService.DAODataService DataServices = new DAODataService.DAODataService();
        try
        {
            // create the objects needed for the process
            XmlDocument Document = new XmlDocument();
            XmlNode Result = null;
            XmlDocument doc = new XmlDocument();
            XslCompiledTransform xslt = new XslCompiledTransform();
            DataSet xmlDataSet = new DataSet();
     
            //Set Variable Values
            string UserCompany = "xxxx";
            string UserName = "xxxxx";
            string UserPassword = "xxxx";
            string sLotBlkUnit = "xxx";
     
            Result = Document.DocumentElement;
            Token = LoginServices.Login(UserCompany, UserName, UserPassword);
            Result = DataServices.GetSubdivisionList(Token, this.uiCboCounty.SelectedValue.ToString(), this.uiTxtSearchFor.Text, "P", sLotBlkUnit, "", "", "", "", "", "");
     
            XmlNode ResultNodes = Document.ImportNode(Result, true);
     
            Document.AppendChild(ResultNodes);
     
            //=============================================
            // save the original data response from titlescan to xml
            //=============================================
            Document.Save("_GetSubdivisionList.xml");
     
            //=============================================
            // need to reformat the xml file to friendly tags so
            // we do it here
            //=============================================
            doc.Load(@"_GetSubdivisionList.xml");
            xslt.Load("GetSubdivisionLotList.xsl");
            xslt.Transform("_GetSubdivisionList.xml", "GetSubdivisionList.xml");
            xmlDataSet.ReadXml("GetSubdivisionList.xml");
     
            //=============================================
            //clear grid from last lookup if applicable
            //=============================================
            this.uiGrdSearchResults.MasterTemplate.Templates.Clear();
            this.uiGrdSearchResults.Relations.Clear();
            
            //=============================================
            // setup the grid and load using the xml data provided
            //=============================================
            GridViewTemplate LotTemplate1 = new GridViewTemplate();
            this.uiGrdSearchResults.MasterTemplate.Templates.Add(LotTemplate1);
            GridViewRelation relation = new GridViewRelation(this.uiGrdSearchResults.MasterTemplate);
            relation.ChildTemplate = LotTemplate1;
            relation.RelationName = "Subdivisions_LotBlockUnits";
            relation.ParentColumnNames.Add("Subdivision_Id");
            relation.ChildColumnNames.Add("LotBlockUnits_Id");
            uiGrdSearchResults.Relations.Add(relation);
     
            if (xmlDataSet.Tables.Count == 0)
            {
                MessageBox.Show("No records found that match the criteria entered.","No Records!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
            }
            else
            {
                this.uiGrdSearchResults.DataSource = xmlDataSet.Tables[0];
                LotTemplate1.DataSource = xmlDataSet.Tables[2];
                this.uiGrdSearchResults.MasterTemplate.BestFitColumns();
                this.uiGrdSearchResults.MasterTemplate.Templates[0].BestFitColumns();
            }
        }
        catch (Exception ex)
        {
            if (Convert.ToString(Token) == "00000000-0000-0000-0000-000000000000")
            {
                MessageBox.Show("Login Failed. Token returned was \n" + Token);
            }
            else
            {
                MessageBox.Show(ex.Message);
            }
        }
        finally
        {
            if (Convert.ToString(Token) != "00000000-0000-0000-0000-000000000000")
            {
                LoginServices.Logout(Token);
            }
        }
     
    }


    The grid will display table[0] correctly with an arrow indicating the child template but when clicking on the arrow the position indicates the child is open but the data does not display.  I have replace table[0] with table[2] as the mastergrid and the data does display as the master data.

    Below is a sample of the XML file data

      <?xml version="1.0" encoding="utf-8" ?>
    - <Subdivisions>
    - <Subdivision>
      <CountyCode>M</CountyCode>
      <Name>CHERRYWOOD VILLAGE CONDO 89-203 POST W/BLKS</Name>
      <Number>CHERRY100</Number>
      <DefinitionFlag>Y</DefinitionFlag>
      <UnitFlag>N</UnitFlag>
      <Comments>UNIT IS LT, BLDG IS BLK EXAMPLE:UNIT 101 BLDG 9500 IS LT 101 BLK 9500 UNIT 9502 BLDG 100 IS LT 950+++</Comments>
    - <LotBlockUnits>
    - <LotBlockUnit>
      <SubdivisionNumber>CHERRY100</SubdivisionNumber>
      <OpenFlag>Y</OpenFlag>
      <Block>100</Block>
      <StartLot>9502</StartLot>
      <EndLot />
      <StartUnit />
      <EndUnit />
      <StartDate />
      <EndDate />
      <UnitComments />
      </LotBlockUnit>
    - <LotBlockUnit>
      <SubdivisionNumber>CHERRY100</SubdivisionNumber>
      <OpenFlag>Y</OpenFlag>
      <Block>100</Block>
      <StartLot>9504</StartLot>
      <EndLot />
      <StartUnit />
      <EndUnit />
      <StartDate />
      <EndDate />
      <UnitComments />
      </LotBlockUnit>
    - <LotBlockUnit>
      <SubdivisionNumber>CHERRY100</SubdivisionNumber>
      <OpenFlag>Y</OpenFlag>
      <Block>100</Block>
      <StartLot>9506</StartLot>
      <EndLot />
      <StartUnit />
      <EndUnit />
      <StartDate />
      <EndDate />
      <UnitComments />
      </LotBlockUnit>
    - <LotBlockUnit>
      <SubdivisionNumber>CHERRY100</SubdivisionNumber>
      <OpenFlag>Y</OpenFlag>
      <Block>100</Block>
      <StartLot>9508</StartLot>
      <EndLot />
      <StartUnit />
      <EndUnit />
      <StartDate />
      <EndDate />
      <UnitComments />
      </LotBlockUnit>
    - <LotBlockUnit>
      <SubdivisionNumber>CHERRY100</SubdivisionNumber>
      <OpenFlag>Y</OpenFlag>
      <Block>100</Block>
      <StartLot>9510</StartLot>
      <EndLot />
      <StartUnit />
      <EndUnit />
      <StartDate />
      <EndDate />
      <UnitComments />
      </LotBlockUnit>
    - <LotBlockUnit>
      <SubdivisionNumber>CHERRY100</SubdivisionNumber>
      <OpenFlag>Y</OpenFlag>
      <Block>100</Block>
      <StartLot>9512</StartLot>
      <EndLot />
      <StartUnit />
      <EndUnit />
      <StartDate />
      <EndDate />
      <UnitComments />
      </LotBlockUnit>
    -</LotBlockUnits>
      </Subdivision>
      </Subdivisions>

    Help!

    Doug
  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 19 Jul 2011 Link to this post

    Hello Doug,

    Thank you for writing.

    I was able to reproduce the issue. If you define the relation before setting the data source to RadGridView, the data will not be shown. So the workaround in this case is to set the DataSource property before defining the relation. I am attaching a sample project which demonstrates the approach.
    You can follow the progress of this issue at this link.

    Your Telerik points have been updated for the report.

    I hope this helps.

    All the best,
    Nikolay
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Doug
    Doug avatar
    26 posts
    Member since:
    Feb 2011

    Posted 19 Jul 2011 Link to this post

    Nikolay,

    Your solution made sense and worked perfectly!  Thank you again for the help.

    Doug
  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 19 Jul 2011 Link to this post

    Hello Doug,

    I am glad to hear that you find my response helpful. Feel free to write back if you have additional questions.

    Best wishes,
    Nikolay
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top