Link to home
Start Free TrialLog in
Avatar of UncleT
UncleTFlag for United States of America

asked on

Canceling the NodeMouseClick for a Treeview in vb.net

Hello,

I've got a VB2010 windows application that has a treeview control in it.  I have several nodes in the Treeview (Call Info, Victim, Witness).  When the application starts the "Call Info" node is always selected.  If the user selects the "Victim" node in the treeView1_NodeMouseClick event I do some validation.  If there is an error in validation I want to cancel out this event and go back to the previous node.  How would I go about doing this.  I am attaching the nodemouseclick code.  If you look at Case 1 you will see where I am trying to set it back to node 0 but when the code fires node 1 is still selected.  Any help would be greatly appreciated.
Private Sub treeView1_NodeMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles treeView1.NodeMouseClick
        Select Case e.Node.Index
            Case 0
                PanelManager1.SelectedPanel = Me.mpCallInfo
            Case 1
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        treeView1.SelectedNode = treeView1.Nodes(0)
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpInformants
            Case 2
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpSuspects
            Case 3
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpVehicles
            Case 4
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpWitnesses
            Case 5
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpContacts
            Case 6
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpAssignments
            Case 7
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpFollowUp
        End Select

    End Sub

Open in new window

Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

try invalidate the tree, in case 1:
Case 1
                If g_lng_Main_PK = 0 Then
                    m_s_Insert_Update()
                    If m_bln_Insert_Update_Error Then
                        treeView1.SelectedNode = treeView1.Nodes(0)
                        treeView1.Invalidate()
                        Exit Select
                    End If
                End If
                PanelManager1.SelectedPanel = Me.mpInformants
Note: I am assuming is Winforms.
ASKER CERTIFIED SOLUTION
Avatar of omegaomega
omegaomega
Flag of Canada 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 UncleT

ASKER

Thanks Randy.  Worked perfectly.