Solved

Canceling the NodeMouseClick for a Treeview in vb.net

Posted on 2011-03-17
3
898 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:UncleT
3 Comments
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 35161065
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.
0
 
LVL 12

Accepted Solution

by:
omegaomega earned 500 total points
ID: 35167122
Hello, UncleT,

I think the problem here is because the node clicked on does not get selected until after the NodeMouseClick event is executed.  I think that you will do better if you use the AfterSelect event to reset the selected node.

Cheers,
Randy
0
 

Author Closing Comment

by:UncleT
ID: 35188857
Thanks Randy.  Worked perfectly.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now