Solved

Kept diaplying TreeNode: ...

Posted on 2009-03-30
7
236 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

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

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

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…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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