473,411 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Re: tree-view item and context menu

My tree is a menu with the parents the different applications (AR, AP,
GL, etc), under each application could be another sub-menu (code file,
reports), or an actual selectable field (customer file).

So, i open AR (by clicking on the plus icon), left-click on customer
file once (so it is highlighted in blue) then right click and select my
menu option. The node that comes back from the cursor position is an
application that is 10 applications down in the list from AR.
Private Sub mAddtoFavorites_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mAddtoFavorites.Click

Dim hti As TreeViewHitTestInfo = trMenu.HitTest(Cursor.Position)
ShowMessage(DRStr(Cursor.Position.X) & " - " & DRStr(Cursor.Position.Y))

If hti.Node Is Nothing Then
Else
Dim xnode As TreeNode
xnode = CType(hti.Node, TreeNode)
ShowMessage(xnode.Text)
End If
End Sub

The customer file that is highlighted is the third one down:

AR
[+] code file
|- Customer File

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
5 1428
On 2008-06-23, Darin <darin_nospam@nospameverwrote:
My tree is a menu with the parents the different applications (AR, AP,
GL, etc), under each application could be another sub-menu (code file,
reports), or an actual selectable field (customer file).

So, i open AR (by clicking on the plus icon), left-click on customer
file once (so it is highlighted in blue) then right click and select my
menu option. The node that comes back from the cursor position is an
application that is 10 applications down in the list from AR.
Private Sub mAddtoFavorites_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles mAddtoFavorites.Click

Dim hti As TreeViewHitTestInfo = trMenu.HitTest(Cursor.Position)
ShowMessage(DRStr(Cursor.Position.X) & " - " & DRStr(Cursor.Position.Y))

If hti.Node Is Nothing Then
Else
Dim xnode As TreeNode
xnode = CType(hti.Node, TreeNode)
ShowMessage(xnode.Text)
End If
End Sub
Darin, try doing it in the ContextMenu.Opening Event, as I showed in the
original code.

--
Tom Shelton
Jun 27 '08 #2
I tried that and it still isn't recognizing the node i am on. Plus, my
context menu has many other options that aren't specific to that node,
just that one option is node-specific.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3
On 2008-06-23, Darin <darin_nospam@nospameverwrote:
I tried that and it still isn't recognizing the node i am on. Plus, my
context menu has many other options that aren't specific to that node,
just that one option is node-specific.

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Well, that's interesting... Because I use this technique all the time :) In
fact, hear is some C# code, from a working application:

private void contextMenu_Opening (object sender, CancelEventArgs e)
{
TreeViewHitTestInfo hitTestInfo = this.tvwObjectExplorer.HitTest ( this.PointToClient (Cursor.Position));
e.Cancel = (hitTestInfo.Node == null || (! (hitTestInfo.Node is LeafNodeBase)));
mnuGenerateEntitiy.Tag = (e.Cancel ? null : hitTestInfo.Node);
}

This is a sample from a small code generation utility I wrote - and it works
perfectly for me. We are dealing with Windows forms right? :)

--
Tom Shelton
Jun 27 '08 #4
My C# is rusty (okay - non-existant) but it looks like you are setting
the tag on the menu to be the node name or the node itself.
You are saying that when you do that, the node is the actual child node
and not the parent. In my example:

AR
[+] Code File
| - Customer File

By right-clicking on Customer File your node would be the node that is
customer file, so the node.text would say that - right?

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #5
On 2008-06-23, Darin <darin_nospam@nospameverwrote:
My C# is rusty (okay - non-existant) but it looks like you are setting
the tag on the menu to be the node name or the node itself.
You are saying that when you do that, the node is the actual child node
and not the parent. In my example:

AR
[+] Code File
| - Customer File

By right-clicking on Customer File your node would be the node that is
customer file, so the node.text would say that - right?

Darin

*** Sent via Developersdex http://www.developersdex.com ***
Yep. My application is similar in that the treeview is a navigation menu -
thought it is dynamically generated by looking at the database schema, but
I only show the context menu on certain kinds of nodes (I have a node hiearchy
whose root is treenode). The node that is assigned to the tag, is the node
that was right clicked on. I'm not suggesting that is the way to do it (set
the tag), you may want to set the selectednode - but that was the way that
worked best for my application :)

--
Tom Shelton
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: pembed2003 | last post by:
Hi, I have a question about how to walk a binary tree. Suppose that I have this binary tree: 8 / \ 5 16 / \ / \ 3 7 9 22 / \ / \ / \
2
by: New | last post by:
Why does this code insert a node into a binary search tree correctly? If I only inserting going by first digit it works properly but when I try inserting going by the whole ip and the port number...
5
by: Mike | last post by:
Why does this code insert a node into a binary search tree correctly? If I only inserting going by first digit it works properly but when I try inserting going by the whole ip and the port number...
2
by: andrew browning | last post by:
gbd says the segmentation fault is being generated in the insert function. //CONSTRUCTOR tree():data(value_type()), left(0), right(0){}; tree(value_type vt, tree* l = 0, tree* r = 0):...
2
by: Kiran | last post by:
Hello all, I am using a tree to display stuff, and it is constantly updated, but what I have noticed is in the lowest level, there is clearly noticable cutoff of the text I place there. The cutoff...
1
by: Satish.Talyan | last post by:
hi, i want to create a dynamic tree hierarchy in javascript.there are two parts in tree, group & user.when we click on group then users come under that's tree category will be opened.problem is...
9
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
4
by: whitehatmiracle | last post by:
Hello I have written a program for a binary tree. On compiling one has to first chose option 1 and then delete or search. Im having some trouble with the balancing function. It seems to be going...
0
by: mac | last post by:
I found that with memory allocating techniques used nowadays (addresses alignment, eg. on 32bit machines) one can detect loops in a tree structure very fast, without using extra memory. This is due...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.