Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to add child node into TreeView?

Posted on 2009-04-07
9
Medium Priority
?
424 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
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
Independent Software Vendors: 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 2000 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

824 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