Solved

Kept diaplying TreeNode: ...

Posted on 2009-03-30
7
235 Views
Last Modified: 2012-05-06
Hi I'm trying to diaplay the Description stored in dr[3] after the last child node so it'll display something like this.
-A01
   -product
      -hardware
         - brand
              alpha: new brand
              beta: current leading brand

But when i generate the following code the last child node kept diaplaying this...
            TreeNode: alpha: new brand
            TreeNode: beta: current leading brand

Why is it so?I'd appreciated if help on the code is offered thanks.
foreach (DataRow dr in ordt.Rows)
                    {
                        nodeCheck = new TreeNode();
                        nodeCheck.Name = dr[0].ToString();                        
                        strText = dr[2].ToString();
                        strDesc = dr[3].ToString();
                        strList = strText.Split('.');
                        nodeCheck.Text = strList[strList.Length - 1];
                        if (dr[1] != DBNull.Value)
                        {
                            node = treeview1.Nodes.Find(dr[1].ToString(), true);
                                if (strList.Length == 5)
                                {
                                    nodeCheck.Text = nodeCheck + ": " + strDesc;
                                    node[0].Nodes.Add(nodeCheck);                                  
                                }
                                else
                                { node[0].Nodes.Add(nodeCheck); }
                        }                        
                        else
                        {
                            treeview1.Nodes.Add(nodeCheck);
                        } 
                        nodeCheck.Tag = dr[0].ToString();
                    }

Open in new window

0
Comment
Question by:csharp_learner
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 24025189
I suspect it's because of line 14. Try to change to:
nodeCheck.Text = strDesc;
0
 

Author Comment

by:csharp_learner
ID: 24025203
I changed it to
nodeCheck.Text = strDesc;
the last child node displayed the description w/o the "TreeNode: "
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 24025293
Isn't this what you want?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:csharp_learner
ID: 24025341
Sorry for the confusion, what i wanted was
nodeCheck.Text = nodeCheck + ": " + strDesc;
Which is in my case "alpha: description"
But the Treeview kept showing "TreeNode: alpha: description"
0
 
LVL 18

Accepted Solution

by:
philipjonathan earned 400 total points
ID: 24025394
You mean without 'nodeCheck + ": " + ' you will not get 'alpha' shown?
nodeCheck.Text = nodeCheck.Text + ": " + strDesc;
0
 

Author Comment

by:csharp_learner
ID: 24025417
nodeCheck.Text = nodeCheck.Text + ": " + strDesc; worked.
Wow did'n know it was just the .text needed thanks.
Any reason for this happening?
0
 
LVL 18

Expert Comment

by:philipjonathan
ID: 24025439
nodeCheck is the object. If you show it on the screen, it will just show the object type, which is "TreeNode". What you need is the Text property of that object, which is "alpha".
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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