×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

C# TreeView Control w/ChildNode

C# TreeView Control w/ChildNode

C# TreeView Control w/ChildNode

(OP)
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);
}




}
}

RE: C# TreeView Control w/ChildNode

(OP)
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);
                    }

                               


            }
        } 

RE: C# TreeView Control w/ChildNode

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close