Context Menu Processing

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

Hello, I have 2 context menu's in which the processing logic for a couple of
the menu items is similar. I was wanting to set up a single procedure for
handling these menu items. My problem is identifying the source of the event.

I thought I would be able to access the MenuItem name, by converting the
"sender" object to a "MenuItem", but when I do, there is no "name" property.
How do I distinquish between to two different menu items in the same
procedure?

Thanks inadvance for your assitance!!!!!!
 
Hi Jim,

Aye, you're right about that name being missing. Strange, huh?

Fortunately you can use:
Select Case DirectCast (sender, MenuItem).Text

Regards,
Fergus
 
Jim Heavey said:
Hello, I have 2 context menu's in which the processing logic for a
couple of the menu items is similar. I was wanting to set up a
single procedure for handling these menu items. My problem is
identifying the source of the event.

I thought I would be able to access the MenuItem name, by converting
the "sender" object to a "MenuItem", but when I do, there is no
"name" property. How do I distinquish between to two different menu
items in the same procedure?

It depends on where you've declared the menu items. If you used the Form
designer, each item is a field of the Form. Assuming the code is within the
same Form:

If Sender Is MyFirstMenuItem Then

ElseIf Sender Is MySecondMenuItem Then

ElseIf...

End If
 
Hello,

Jim Heavey said:
I thought I would be able to access the MenuItem name,
by converting the "sender" object to a "MenuItem", but when
I do, there is no "name" property. How do I distinquish between
to two different menu items in the same
procedure?

\\\
If sender Is Me.MenuItem1 Then
...
ElseIf sender Is Me.MenuItem2 Then
...
Else
...
End If
///
 
Hello,

Fergus Cooney said:
Aye, you're right about that name being missing. Strange, huh?

Fortunately you can use:
Select Case DirectCast (sender, MenuItem).Text

Noitce that this will only work if there are not 2 menu items with the same
text but different functionality.
 
Hi Herfried,

|| > Fortunately you can use:
|| > Select Case DirectCast (sender, MenuItem).Text
||
|| Noitce that this will only work if there are not 2 menu items
|| with the same text but different functionality

Within the same MenuItem_Click handler. ;-)

Regards,.
Fergus
 
Hello,

Fergus Cooney said:
Within the same MenuItem_Click handler. ;-)

I am not really sure what the sense of the question is. On the one hand
same functionality whould be handled in the same handler, on the other hand
he wants to distinguish between the different menu items.
 
Back
Top