Solved

How to add child node into TreeView?

Posted on 2009-04-07
9
417 Views
Last Modified: 2012-05-06
Hi, I currently have a Treeview which populates something like this
-X01
   -product
      -hardware
         - brand
              alpha
              beta
+X02
I'm connecting to another database for the last node.Due to the heavy load in the database i've decided to load it after the afterselect event.Like the code I've included.

What I aim to achieve is something like this...
-X01
   -product
      -hardware
         - brand
              -alpha
                  -alpha.101(read from new database)
                  -alpha.102(read from new database)
              beta
+X02

I hope someone can help me out.And i'm not very proficient in my programming so I'd appreciate it if your solution come in codes thanks in advance.
private void treeview1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (e.Node.Level != 4)
            { return; }
            else
            {
                    localSQL = "SELECT KEYID,PRODUCT_NAME,PRODUCT_DESC,PKEYID,PRODUCT_TYPE FROM PRODUCT_PT WHERE PKEYID LIKE '" + treeview1.SelectedNode.Name + "'";
                    OracleCommand cmdOracle = new OracleCommand(localSQL, localConnection);
                    cmdOracle.CommandType = CommandType.Text;
                    OracleDataReader drO= cmdOracle.ExecuteReader();
                    while (drO.Read())
                    {
                    // Add node...???
                    }
                    drOracle.Close();
            }
        }

Open in new window

0
Comment
Question by:csharp_learner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24085649
is this WPF ? then
while (drO.Read())
{
TreeViewItem Item = new TreeViewItem();
Item.Content = "Ur Text";
e.Node.Items.Add(Item);
}

Open in new window

0
 
LVL 6

Expert Comment

by:SaedSalman
ID: 24086812

while (drO.Read())
{
TreeViewItem item = new TreeViewItem();
Item.Content = "Text to add";  //if SELECT result then:drO[0].ToString()
treeview1.Node.Items.Add(item);
}

Open in new window

0
 

Author Comment

by:csharp_learner
ID: 24093332
Sorry to left  it out, but this is C# win forms.
I tried the following code but there are errors on the 3rd line...
                        TreeView item = new TreeView();
                        item = drOracle.GetOracleString(1).ToString();
                        treeview1.Node.item.Add(item);
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24093813

 item.Text = drOracle.GetOracleString(1).ToString();
0
 

Author Comment

by:csharp_learner
ID: 24093842
item.Text cannot be found in the list only Name can be found and i used it but line 3 is still in error.
Thanks for your reply.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 24094959
treeview1.Nodes.Add(Item);
0
 

Author Comment

by:csharp_learner
ID: 24095028
I tried using
                            TreeView item = new TreeView();
                            item.Name = drOracle.GetOracleValue(4).ToString();
                            treeview1.Nodes.Add(item);

But 2 compile errors came out,both is based on line 3.

1.The best overloaded method match for 'System.Windows.Forms.TreeNodeCollection.Add(System.Windows.Forms.TreeNode)' has some invalid arguments.

2.Argument '1': cannot convert from 'System.Windows.Forms.TreeView' to 'System.Windows.Forms.TreeNode'
0
 
LVL 1

Accepted Solution

by:
prakhardeep earned 500 total points
ID: 24095144
You cannot add a treeview (line 1) to treenode (line 3).

Try the following:


TreeNode node = new TreeNode();
node.Text = drOracle.GetOracleValue(4).ToString();
e.Node.Nodes.Add(node);

Open in new window

0
 

Author Closing Comment

by:csharp_learner
ID: 31567412
Exactly what i was looking for Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and theā€¦
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question