Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# TreeView Control w/ChildNode

Status
Not open for further replies.

Christineeve

Programmer
Feb 12, 2005
104
0
0
US
Dear Coding Gurus:
My code is created the childnode twice. I cannot figure out what I'm doing wrong. I should have a tree that looks like this:

Subject -
Parent
Child
Subject
Parent
Child

What my code is doing is populating the child twice.
Code:
        protected void trvMsgBoard_TreeNodePopulate(
          object sender, TreeNodeEventArgs e)
        {
            if (e.Node.ChildNodes.Count == 0)
            {
                switch (e.Node.Depth)
                {
                    case 0:
                        PopulateThread(e.Node);
                        break;
                    case 1:
                        PopulateSubTopics(e.Node);
                        break;
                }
            }
        }

        //State what level the tree node is on for the developer.

        void PopulateThread(TreeNode node) //Parent Node
        {

            DataTable dtSRS = DAL.Oracle_ReturnDataTable_SQLString_NoParams("SELECT WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID," +
                                                                        " WDSDEV.DZR_FORUM_TOPIC.TOPIC_TOPIC," +
                                                                        "   WDSDEV.DZR_FORUM_TOPIC.TOPIC_DATETIME" +
                                                                        " FROM WDSDEV.DZR_FORUM_TOPIC", Oracle_connstr1, "dtSRS");          

            using (DataSet dsSRS = new DataSet())
            {
                dsSRS.Tables.Add(dtSRS);
                if (dsSRS.Tables.Count > 0)
                    foreach (DataRow row in dsSRS.Tables[0].Rows)
                    {
                        TreeNode NewNode = new TreeNode(row["TOPIC_TOPIC"].ToString(), row["TOPIC_TOPIC"].ToString())
                        { PopulateOnDemand = true,
                        SelectAction = TreeNodeSelectAction.Expand };
                        node.ChildNodes.Add(NewNode);
                    }
            }

        }


        void PopulateSubTopics(TreeNode node)  //child not
       
        {
         

            DataTable dtPST = DAL.Oracle_ReturnDataTable_SQLString_NoParams(
                 " SELECT * " +
              " FROM WDSDEV.DZR_FORUM_SUB_TOPIC " +
               " INNER JOIN WDSDEV.DZR_FORUM_TOPIC" +
             " ON WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID = WDSDEV.DZR_FORUM_SUB_TOPIC.TOP_ID" +
             " INNER JOIN WDSDEV.DZR_FORUM_AUTHOR" +
              " ON WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID = WDSDEV.DZR_FORUM_AUTHOR.FK_TOP_ID" , Oracle_connstr1, "dtPST");

            using (DataSet dsPST = new DataSet())
            {
                
                dsPST.Tables.Add(dtPST);                
                if (dsPST.Tables.Count > 0)
                    foreach (DataRow row in dsPST.Tables[0].Rows)
                    {
                        TreeNode NewNode = new TreeNode(row["SUBTOP_TOPIC"].ToString(), row["SUBTOP_TOPIC"].ToString());
                        NewNode.PopulateOnDemand = false;
                        NewNode.SelectAction = TreeNodeSelectAction.Expand;
                        node.ChildNodes.Add(NewNode);
                    }

                               


            }
        }
 
Oops. Here is a more clear version of my code. Thank you for any help.

Code:
        protected void trvMsgBoard_TreeNodePopulate(
          object sender, TreeNodeEventArgs e)
        {
            if (e.Node.ChildNodes.Count == 0)
            {
                switch (e.Node.Depth)
                {
                    case 0:
                        PopulateThread(e.Node);
                        break;
                    case 1:
                        PopulateSubTopics(e.Node);
                        break;
                }
            }
        }

        //State what level the tree node is on for the developer.

        void PopulateThread(TreeNode node) //Parent Node
        {

            DataTable dtSRS = DAL.Oracle_ReturnDataTable_SQLString_NoParams("SELECT 
            WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID," +
           " WDSDEV.DZR_FORUM_TOPIC.TOPIC_TOPIC," +
           "   WDSDEV.DZR_FORUM_TOPIC.TOPIC_DATETIME" +
           " FROM WDSDEV.DZR_FORUM_TOPIC", Oracle_connstr1, "dtSRS");          

            using (DataSet dsSRS = new DataSet())
            {
                dsSRS.Tables.Add(dtSRS);
                if (dsSRS.Tables.Count > 0)
                    foreach (DataRow row in dsSRS.Tables[0].Rows)
                    {
                        TreeNode NewNode = new TreeNode(row["TOPIC_TOPIC"].ToString(),
                        row["TOPIC_TOPIC"].ToString())
                        { PopulateOnDemand = true,
                        SelectAction = TreeNodeSelectAction.Expand };
                        node.ChildNodes.Add(NewNode);
                    }
            }

        }


        void PopulateSubTopics(TreeNode node)  //child node
 
        {
         

            DataTable dtPST = DAL.Oracle_ReturnDataTable_SQLString_NoParams(
                 " SELECT * " +
                 " FROM WDSDEV.DZR_FORUM_SUB_TOPIC " +
                 " INNER JOIN WDSDEV.DZR_FORUM_TOPIC" +
                 " ON WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID = WDSDEV.DZR_FORUM_SUB_TOPIC.TOP_ID" +
                 " INNER JOIN WDSDEV.DZR_FORUM_AUTHOR" +
                 " ON WDSDEV.DZR_FORUM_TOPIC.TOPIC_ID = WDSDEV.DZR_FORUM_AUTHOR.FK_TOP_ID", 
                  Oracle_connstr1, "dtPST");

            using (DataSet dsPST = new DataSet())
            {
                
                dsPST.Tables.Add(dtPST);                
                if (dsPST.Tables.Count > 0)
                    foreach (DataRow row in dsPST.Tables[0].Rows)
                    {
                        TreeNode NewNode = new TreeNode(row["SUBTOP_TOPIC"].ToString(),
                        row ["SUBTOP_TOPIC"].ToString());
                        NewNode.PopulateOnDemand = false;
                        NewNode.SelectAction = TreeNodeSelectAction.Expand;
                        node.ChildNodes.Add(NewNode);
                    }

                               


            }
        }
 
Are the number of rows returned the correct amount? Just checking that they are not duplicated in some DB join....


Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top