PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Context menus and treeviews, suggestions for a NODE sensitive context menu

 
 
Eric Newton
Guest
Posts: n/a
 
      12th Jan 2004
Easy part is creating a context menu for a specific node

(one of several examples follows)
Private Sub treeview_MouseUp(byval sender as object, byval e as
MouseEventArgs) handles TreeView1.MouseUp
if e.Button = MouseButtons.Right then
Dim node as TreeNode = TreeView1.GetNodeAt(e.X,e.Y)
if not node is nothing then
if typeof node is TYPE1 then

ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE1)))
elseif typeof node is TYPE2 then

ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE2)))
'... and so on ...
end if
end if
end if
end if

NOW Heres the problem:

Once a menu item is clicked, how does one accurately get the node that
triggered the whole set of operations?

Answer is, you cant... since MenuItems dont have TAGS you cannot associate
Clicks events with actual data.

A serious flaw in the MenuItem class in my opinion


--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(E-Mail Removed) [remove the first "CC."]



 
Reply With Quote
 
 
 
 
Iulian Ionescu
Guest
Posts: n/a
 
      12th Jan 2004

You can inherit the MenuItem class and add the Tag
property... It will work very well...

>-----Original Message-----
>Easy part is creating a context menu for a specific node
>
>(one of several examples follows)
>Private Sub treeview_MouseUp(byval sender as object,

byval e as
>MouseEventArgs) handles TreeView1.MouseUp
> if e.Button = MouseButtons.Right then
> Dim node as TreeNode = TreeView1.GetNodeAt

(e.X,e.Y)
> if not node is nothing then
> if typeof node is TYPE1 then
>
>ShowContextMenu(BuildContextMenu(DirectCast

(node.Tag,TYPE1)))
> elseif typeof node is TYPE2 then
>
>ShowContextMenu(BuildContextMenu(DirectCast

(node.Tag,TYPE2)))
> '... and so on ...
> end if
> end if
> end if
>end if
>
>NOW Heres the problem:
>
>Once a menu item is clicked, how does one accurately get

the node that
>triggered the whole set of operations?
>
>Answer is, you cant... since MenuItems dont have TAGS

you cannot associate
>Clicks events with actual data.
>
>A serious flaw in the MenuItem class in my opinion
>
>
>--
>Eric Newton
>C#/ASP Application Developer
>http://ensoft-software.com/
>(E-Mail Removed) [remove the first "CC."]
>
>
>
>.
>

 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      12th Jan 2004
* "Eric Newton" <(E-Mail Removed)> scripsit:
> Easy part is creating a context menu for a specific node
>
> (one of several examples follows)
> Private Sub treeview_MouseUp(byval sender as object, byval e as
> MouseEventArgs) handles TreeView1.MouseUp
> if e.Button = MouseButtons.Right then
> Dim node as TreeNode = TreeView1.GetNodeAt(e.X,e.Y)
> if not node is nothing then
> if typeof node is TYPE1 then
>
> ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE1)))
> elseif typeof node is TYPE2 then
>
> ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE2)))
> '... and so on ...
> end if
> end if
> end if
> end if
>
> NOW Heres the problem:
>
> Once a menu item is clicked, how does one accurately get the node that
> triggered the whole set of operations?
>
> Answer is, you cant... since MenuItems dont have TAGS you cannot associate
> Clicks events with actual data.


You may want to inherit from 'MenuItem' and extend it by a 'Tag'
property. Notice that this will break compatibility with the menu
designer.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
 
Reply With Quote
 
Doug Forster
Guest
Posts: n/a
 
      13th Jan 2004
Hi Eric,

Did you read my response to the same question on 24/12 ?

Cheers

Doug Forster

"Eric Newton" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Easy part is creating a context menu for a specific node
>
> (one of several examples follows)
> Private Sub treeview_MouseUp(byval sender as object, byval e as
> MouseEventArgs) handles TreeView1.MouseUp
> if e.Button = MouseButtons.Right then
> Dim node as TreeNode = TreeView1.GetNodeAt(e.X,e.Y)
> if not node is nothing then
> if typeof node is TYPE1 then
>
> ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE1)))
> elseif typeof node is TYPE2 then
>
> ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE2)))
> '... and so on ...
> end if
> end if
> end if
> end if
>
> NOW Heres the problem:
>
> Once a menu item is clicked, how does one accurately get the node that
> triggered the whole set of operations?
>
> Answer is, you cant... since MenuItems dont have TAGS you cannot associate
> Clicks events with actual data.
>
> A serious flaw in the MenuItem class in my opinion
>
>
> --
> Eric Newton
> C#/ASP Application Developer
> http://ensoft-software.com/
> (E-Mail Removed) [remove the first "CC."]
>
>
>



 
Reply With Quote
 
Eric Newton
Guest
Posts: n/a
 
      13th Jan 2004
actually i had not seen your post, which is bizarre cause i usually "have
Show Replies to my messages" checked...

Anyways, I liked your suggestion, however, it just seems like the context
menu should probably remember this itself, and be able to present it to
Click events

or better yet, MenuItems have a Select event (or whatever it wouldbe called)
with a lot more info in the EventArgs

thanks though, Doug
--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
(E-Mail Removed) [remove the first "CC."]

"Doug Forster" <doug_ZAPTHIS_AT_TONIQ_ZAPTHIS_co.nz> wrote in message
news:(E-Mail Removed)...
> Hi Eric,
>
> Did you read my response to the same question on 24/12 ?
>
> Cheers
>
> Doug Forster
>
> "Eric Newton" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Easy part is creating a context menu for a specific node
> >
> > (one of several examples follows)
> > Private Sub treeview_MouseUp(byval sender as object, byval e as
> > MouseEventArgs) handles TreeView1.MouseUp
> > if e.Button = MouseButtons.Right then
> > Dim node as TreeNode = TreeView1.GetNodeAt(e.X,e.Y)
> > if not node is nothing then
> > if typeof node is TYPE1 then
> >
> > ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE1)))
> > elseif typeof node is TYPE2 then
> >
> > ShowContextMenu(BuildContextMenu(DirectCast(node.Tag,TYPE2)))
> > '... and so on ...
> > end if
> > end if
> > end if
> > end if
> >
> > NOW Heres the problem:
> >
> > Once a menu item is clicked, how does one accurately get the node that
> > triggered the whole set of operations?
> >
> > Answer is, you cant... since MenuItems dont have TAGS you cannot

associate
> > Clicks events with actual data.
> >
> > A serious flaw in the MenuItem class in my opinion
> >
> >
> > --
> > Eric Newton
> > C#/ASP Application Developer
> > http://ensoft-software.com/
> > (E-Mail Removed) [remove the first "CC."]
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access2007 Context-sensitive menus Wierdbeard65 Microsoft Access VBA Modules 0 15th Nov 2009 05:41 PM
Context Sensitive Drop Down Menus Sam Bench Microsoft Excel Discussion 2 8th Jun 2007 08:21 PM
Context menu popup on treeview node returning wrong selected node Claire Microsoft C# .NET 2 5th Mar 2007 12:59 PM
Context Sensitive Web Menus in ASP.NET Kayhan Microsoft ASP .NET 1 29th Mar 2004 08:11 PM
Re: Contect Menu Editor (Context Menu Editor / Context Menu Manager) BillR Freeware 5 13th Aug 2003 04:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:47 PM.