Solved

Treeview Nodes not showing - no exceptions being thrown

Posted on 2014-02-06
6
312 Views
Last Modified: 2014-02-08
The Treenode I am using works well in most cases, but there is a method in which the nodes are not being added -- and there are no exceptions being thrown.   The default approach is to search for a node name, and then add the node.

In a Public Module for Declarations: the delegate is defined as:

  Public Delegate Sub AppendTreeviewDelegate(ByVal level, ByVal txtstr, ByVal pathstr, ByVal resimgname)

Open in new window


The method which adds nodes is in the Form1 Class and is:

 Public Sub appendtreeview(ByVal level, ByVal txtstr, ByVal pathstr, ByVal resimgname)
   
        If level = 0 Then
            TreeView1.BeginUpdate()
            TreeView1.Nodes.Add(RootDataControlName, txtstr, resimgname)
            TreeView1.EndUpdate()
        Else
            TreeView1.BeginUpdate()
            TreeView1.Nodes.Find(RootDataControlName, True)(0).Nodes.Add(CurrentTaskControlName, txtstr, resimgname).tag = pathstr
            TreeView1.EndUpdate()
        End If
        TreeView1.ExpandAll()
        TreeView1.Refresh()
  End Sub

Open in new window


The code inside the threaded method (inside an instantiated class):

        Dim appendtreeviewdel As AppendTreeviewDelegate = New AppendTreeviewDelegate(AddressOf Form1.appendtreeview)
        Dim main As Form1 = CType(Application.OpenForms(0), Form1)

        level = 1
        txtstr = "test"
        filename = "c:\test.txt"  
        resimgname = "testimage"
        main.BeginInvoke(New AppendTreeviewDelegate(AddressOf Form1.appendtreeview), {level, txtstr, filename, resimgname})
  

Open in new window


A level=0 does exist, so the new nodes should be added at level=1.   Also, all of the parameter values are correct: filenames ("pathstr"), and "testimage" is a valid image in My.Resources, etc.  I have even tried the code below, which does not search for the name of a parent node, but rather directly forces the creation of the new node, however, no luck, and no exceptions are being thrown:

  TreeView1.Nodes.Add(CurrentTaskControlName, txtstr, resimgname).tag = pathstr

Open in new window

         

Any suggestions?
0
Comment
Question by:lep1
  • 3
  • 2
6 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39839749
Does it work if you use the Add(NodeText) method?
0
 

Author Comment

by:lep1
ID: 39841129
No.  Treeview1.Nodes.Add(txtstr) did not work.
0
 
LVL 27

Expert Comment

by:Ark
ID: 39841342
Are you sure you need BeginInvoke/EndInvoke to get async result? Why not just use main.invoke(...)?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:lep1
ID: 39841716
Changed BeginInvoke to Invoke, and nothing doing (didn't work),
0
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 39843779
Is your class instance really run in different thread? Try check if invoke required:
If main.InvokeRequired Then
   main.invoke(...)
Else
   main.appendtreeview(...)
End If

Open in new window

BTW, your call to delegate should points to Form1 instance method, not Form1 type method:
New AppendTreeviewDelegate(AddressOf main.appendtreeview ...
0
 

Author Closing Comment

by:lep1
ID: 39844395
Great recommendation. It was due to changing Form1 to main.   Thx.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now