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:
The method which adds nodes is in the Form1 Class and is:
The code inside the threaded method (inside an instantiated class):
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:
Any suggestions?
In a Public Module for Declarations: the delegate is defined as:
Public Delegate Sub AppendTreeviewDelegate(ByVal level, ByVal txtstr, ByVal pathstr, ByVal resimgname)
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
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})
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
Any suggestions?
Does it work if you use the Add(NodeText) method?
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(...)?
ASKER
Changed BeginInvoke to Invoke, and nothing doing (didn't work),
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great recommendation. It was due to changing Form1 to main. Thx.