Treeview Help

  • Thread starter Thread starter A-PK
  • Start date Start date
A

A-PK

Hi,

I am using treeview as my menu.
my menu is like the following

+ Users & Groups
- Users
-Groups
+ Departmenuts
- Engineering
- Business

Currently, I am using mouse down event and trigger my mouse right click.
so when my mouse cursor is in the treeview, and I right click my mouse, my
context menu1 will show up.

but, what I want to do is like the following

When i right click the - Users - pop up context menu1
When I right click the - Groups - pop up context menu2
When I right click the - Engineering - pop up context menu3
When I right click the - Business - pop up context menu4

When I right click the + Users & Groups, nothing will pop up
When I right click the + Departments, nothing will pop up

how to do that ? pls guide me.
 
To elaborate further on Ken's reply:

In the mousedown event:
1. check to see if the right mouse button was clicked
2. If yes, detect which node was clicked
3. create the appropriate context menu
4. show the context menu

--------------------
From: "Ken Tucker [MVP]" <[email protected]>
References: <[email protected]>
Subject: Re: Treeview Help
Date: Thu, 26 Feb 2004 07:15:27 -0500
Lines: 40
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.general,microsoft.public.dotnet.languages.vb,microso
ft.public.vstudio.development,microsoft.public.vstudio.general
NNTP-Posting-Host: adsl-18-39-198.mco.bellsouth.net 68.18.39.198
Path: cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:184878
microsoft.public.vstudio.development:4455
microsoft.public.vstudio.general:5658 microsoft.public.dotnet.general:126200
 
Hi,

Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown

Dim n As TreeNode

Dim myContextMenu As ContextMenu

If e.Button = MouseButtons.Right Then

Try

n = TreeView1.GetNodeAt(e.X, e.Y)

' figure out which menu to display

myContextMenu.Show(TreeView1, New Point(e.X, e.Y))

Catch ex As Exception

'didn't click on a node ignore the event

End Try

End If

End Sub



Ken
 
Hy Ken,

in addition to this:

how can I select a treenode with the MouseButtons.Right event if there is no
contextmenu?

I build up a treeview with 3 levels. Only if the second level is selected,
there should be a contextmenu.
This works without problems. In between this level I can select the next
node with the mouseButtons.Right because there is a contextmenu.
If I try to select a node of the first or third level , it gets selected by
holding the mousedown, but with mouseup it jumps back to the origin.
Is there a possibility to handle this?

Greetings Joerg

Ken Tucker said:
Hi,

Private Sub TreeView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseDown

Dim n As TreeNode

Dim myContextMenu As ContextMenu

If e.Button = MouseButtons.Right Then

Try

n = TreeView1.GetNodeAt(e.X, e.Y)

' figure out which menu to display

myContextMenu.Show(TreeView1, New Point(e.X, e.Y))

Catch ex As Exception

'didn't click on a node ignore the event

End Try

End If

End Sub



Ken
 
Back
Top