Link to home
Start Free TrialLog in
Avatar of lep1
lep1

asked on

Treeview Nodes not showing - no exceptions being thrown

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?
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Does it work if you use the Add(NodeText) method?
Avatar of lep1
lep1

ASKER

No.  Treeview1.Nodes.Add(txtstr) did not work.
Are you sure you need BeginInvoke/EndInvoke to get async result? Why not just use main.invoke(...)?
Avatar of lep1

ASKER

Changed BeginInvoke to Invoke, and nothing doing (didn't work),
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lep1

ASKER

Great recommendation. It was due to changing Form1 to main.   Thx.