Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Canceling the NodeMouseClick for a Treeview in vb.net

Posted on 2011-03-17
3
Medium Priority
?
975 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 2000 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

Technology Partners: 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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 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