G
Guest
Hi,
I've a problem with setting the selectednode in a treeview. When a user
clicks a node on the tree, I save the data for the previous node, and store
the newnode in a variable in the Mouse up event. Then I reuild the tree, and
set the SelectedNode to the newnode. I can see that the selected node is
correct till the AfterSelect event - correct in BeforeSelect event. But in
the AFterSelect the SelectedNode changes to a random node. I tried to set the
correct node in the AfterSelect, but it shows this random node. If I set the
selected node to nothing, it becomes nothing, but I cannot set it to this
newnode selected by the user.Can someone suggest what to do here.
Thanx in Advance,
Debi
***************************************
Private Sub tvSchedule_AfterSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles tvSchedule.AfterSelect
Try
Dim Mydate As Date
Dim CurrRow As DataRow
Dim drTreeTag As DataRow
If bTreeMove Or bReload Then Exit Sub
If Not tvSchedule Is Nothing And Not CurrTreeNode Is Nothing Then
If bBugFix And (tvSchedule.SelectedNode.Text <>
CurrTreeNode.Text) Then
tvSchedule.SelectedNode = Nothing
tvSchedule.SelectedNode = CurrTreeNode
bBugFix = False
End If
End If
CurrTreeNode = tvSchedule.SelectedNode
----------------------------------------------------------------------------------------------
Private Sub tvSchedule_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles tvSchedule.MouseUp
Try
Dim pt As Point
pt = New Point(e.X, e.Y)
CurrTreeNode = CType(sender, TreeView).GetNodeAt(pt)
If Not bReload Then
tvSchedule.SelectedNode = CurrTreeNode
End If
If bReload Then
ReloadTree()
bBugFix = True
End If
--------------------------------------------------------------------------------------------
Private Sub tvSchedule_AfterExpand(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles tvSchedule.AfterExpand
If Not bTreeLoad Then tvSchedule.SelectedNode = e.Node()
End Sub
--------------------------------------------------------------------------------------------
Private Sub tvSchedule_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tvSchedule.Click
Try
bTreeClick = True
savedata()
bTreeClick = False
Catch ex As Exception
ShowMessage("Exception Tree Click", AppName, 1)
Finally
End Try
End Sub
I've a problem with setting the selectednode in a treeview. When a user
clicks a node on the tree, I save the data for the previous node, and store
the newnode in a variable in the Mouse up event. Then I reuild the tree, and
set the SelectedNode to the newnode. I can see that the selected node is
correct till the AfterSelect event - correct in BeforeSelect event. But in
the AFterSelect the SelectedNode changes to a random node. I tried to set the
correct node in the AfterSelect, but it shows this random node. If I set the
selected node to nothing, it becomes nothing, but I cannot set it to this
newnode selected by the user.Can someone suggest what to do here.
Thanx in Advance,
Debi
***************************************
Private Sub tvSchedule_AfterSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles tvSchedule.AfterSelect
Try
Dim Mydate As Date
Dim CurrRow As DataRow
Dim drTreeTag As DataRow
If bTreeMove Or bReload Then Exit Sub
If Not tvSchedule Is Nothing And Not CurrTreeNode Is Nothing Then
If bBugFix And (tvSchedule.SelectedNode.Text <>
CurrTreeNode.Text) Then
tvSchedule.SelectedNode = Nothing
tvSchedule.SelectedNode = CurrTreeNode
bBugFix = False
End If
End If
CurrTreeNode = tvSchedule.SelectedNode
----------------------------------------------------------------------------------------------
Private Sub tvSchedule_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles tvSchedule.MouseUp
Try
Dim pt As Point
pt = New Point(e.X, e.Y)
CurrTreeNode = CType(sender, TreeView).GetNodeAt(pt)
If Not bReload Then
tvSchedule.SelectedNode = CurrTreeNode
End If
If bReload Then
ReloadTree()
bBugFix = True
End If
--------------------------------------------------------------------------------------------
Private Sub tvSchedule_AfterExpand(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles tvSchedule.AfterExpand
If Not bTreeLoad Then tvSchedule.SelectedNode = e.Node()
End Sub
--------------------------------------------------------------------------------------------
Private Sub tvSchedule_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles tvSchedule.Click
Try
bTreeClick = True
savedata()
bTreeClick = False
Catch ex As Exception
ShowMessage("Exception Tree Click", AppName, 1)
Finally
End Try
End Sub