Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Treeview Nodes not showing - no exceptions being thrown

Posted on 2014-02-06
6
Medium Priority
?
320 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 Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

618 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