Solved

Canceling the NodeMouseClick for a Treeview in vb.net

Posted on 2011-03-17
3
959 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 36

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

617 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