|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Changing Treeview's selectedNode in Afterselect event.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 You're saving the selected node in a variable and then clearing
and repopulating the tree, correct? Do you insert it again? I.e. do you do tvSchedule.Nodes.Add(CurrTreeNode)? If you don't then CurrTreeNode doesn't exist in the tree anymore (since you cleared the tree), so you won't find it there. The SelectedNode property selects the EXACT instance of the node that you're providing. If that instance isn't inserted into the tree nothing will happen. It doesn' matter if there is a node with the same text etc. If it's not the exact same instance nothing will happen /claes Show quoteHide quote "Debi" <debi@nospam.com> wrote in message news:B3AE0F60-6514-41B6-926D-60925388D7B6@microsoft.com... > 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
Other interesting topics
No touch deployment - IEEXEC won't fire up
No popup event when using shortcuts in context menu How can one select from overlapped panels in the form design View? How to add tabpage to tabcontrol at 1st tab? extra header in datagrid Is there a way to set the category order in the PropertyGrid Error lost in databinding PictureBox that Receives and Shows Input Focus Check-boxes on TreeNodes SteadySelection Class |
|||||||||||||||||||||||