?
Solved

Treeview Nodes not showing - no exceptions being thrown

Posted on 2014-02-06
6
Medium Priority
?
319 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
[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
  • 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 28

Expert Comment

by:Ark
ID: 39841342
Are you sure you need BeginInvoke/EndInvoke to get async result? Why not just use main.invoke(...)?
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

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

Accepted Solution

by:
Ark earned 2000 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

Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

752 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