Solved

Treeview Nodes not showing - no exceptions being thrown

Posted on 2014-02-06
6
314 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 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…
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…

810 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