Solved

Canceling the NodeMouseClick for a Treeview in vb.net

Posted on 2011-03-17
3
926 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating a route in asp.net webforms 2 32
Call windows 10 virtual keyboard from windows forms app 2 53
MYSQL responding very slow 3 26
Access Schema 6 27
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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