Hello all
I'm developing a windows application. I have a form in which there is a list box and a treeview control. My purpose is to fill treeview according to list item clicks. This is done using a pair of subroutines called ReloadPermissions and FillMenuItem:
When list is clicked, ReloadPermissions is called:
There are only two subroutines in which nodes are added to treeview control, and they are subroutines above. The problem is that whenever list item is clicked, node count displayed in treeview is increased!!! I checked number of nodes before and after call to tvPermissions.Nodes.Clear() using MsgBox. Results show that number of nodes isn't increased (1 before call, 0 after call, again 1 after ReloadPermissions() is called), but what is displayed doesn't show such a behavior! Refreshing window by putting it under other windows or call to tvPermissions.Refresh() has no effect.
Can anybody help me?!
I'm developing a windows application. I have a form in which there is a list box and a treeview control. My purpose is to fill treeview according to list item clicks. This is done using a pair of subroutines called ReloadPermissions and FillMenuItem:
VB.NET:
Private Sub ReloadPermissions()
Dim p As New Permissions
Dim i As Integer
Dim it As TreeNode
Dim el As New List(Of String)
p.LoadEntire(Main.DBC, 0)
GetExpandedItems(tvPermissions.Nodes, el)
tvPermissions.Nodes.Clear()
For i = 0 To p.Count - 1
it = New TreeNode
it.Text = p(i).UrlText
it.Tag = p(i).ID
If p(i).Hidden Then it.ForeColor = Color.Red
tvPermissions.Nodes.Add(it)
FillMenuItem(it, p(i))
Next
el.Sort()
ExpandItems(tvPermissions.Nodes, el)
End Sub
Private Sub FillMenuItem(ByRef tn As TreeNode, ByVal P As Permission)
Dim i As Integer
Dim it As TreeNode
For i = 0 To P.Children.Count - 1
it = New TreeNode
it.Text = P.Children(i).UrlText
it.Tag = P.Children(i).ID
If P.Children(i).Hidden Then it.ForeColor = Color.Red
tn.Nodes.Add(it)
FillMenuItem(it, P.Children(i))
Next
End Sub
When list is clicked, ReloadPermissions is called:
VB.NET:
Private Sub lstTemplates_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstTemplates.Click
If lstTemplates.SelectedIndex < 0 Then Exit Sub
Dim s As String = lstTemplates.SelectedItem.ToString
Dim tm As New PermissionTemplate(Main.DBC, CType(lstTemplates.SelectedItem, ListItem).Value)
ReloadPermissions()
CheckPermissions(tm.Permissions)
txtTitle.Text = tm.Title
rbEdit.Select()
End Sub
There are only two subroutines in which nodes are added to treeview control, and they are subroutines above. The problem is that whenever list item is clicked, node count displayed in treeview is increased!!! I checked number of nodes before and after call to tvPermissions.Nodes.Clear() using MsgBox. Results show that number of nodes isn't increased (1 before call, 0 after call, again 1 after ReloadPermissions() is called), but what is displayed doesn't show such a behavior! Refreshing window by putting it under other windows or call to tvPermissions.Refresh() has no effect.
Can anybody help me?!