Progamming manually a Context Menu Items 
Author Message
 Progamming manually a Context Menu Items

Hi,

I have a context Menu that I am adding to via code. The items are all added
fine to my contextmenu

CtxContactArray.MenuItems.Add(Trim(ContactName), New
System.EventHandler(AddressOf Me.Checked_OnClick))

The number of items I am adding to the context menu always changes, as its a
list of contacts selected a sql table(select id, ContactName from tbl). What

I want to do is do be able to get the contact_ID of the contact the user has
selected. The above menuitems.add code add in all the contactname all very
nice, and no matter what name I select from the context menu, the protected
sub Checked_onClick is called.

My Problem is that within the the sub Checked_OnClick, I actually need to
use the ID value, not the name.

How should I do this one....

Thanks All



Wed, 21 Sep 2005 23:09:25 GMT  
 Progamming manually a Context Menu Items
Hi HPD, what you can do is create your own class that inherits a menuitem,
and add a property for Contact_ID, For this example, I'll Assume Contact_ID
is an Integer:
'<watch for wrapping>
Public Class MyMenuItem
    Inherits MenuItem

    Private m_ContactID As Integer

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(strText As String, intContactID As Integer,
ehEventHandler As System.EventHandler)
        MyBase.New(strText, ehEventHandler)
        m_ContactID = intContactID
    End Sub

    Public Property ContactID() As Integer
        Get
            Return m_ContactID
        End Get
        Set (Value As Integer)
            m_ContactID = Value
        End Set
    End Property
End Class
'</watch for wrapping>

Now your class is created, you can do the following:

'<watch for wrapping>
Dim intContactID As Integer = 5
CtxContactArray.MenuItems.Add(New MyMenuItem(Trim(ContactName),
intContactID, New System.EventHandler(AddressOf Me.Checked_OnClick)))
'</watch for wrapping>

And in your click event:

Public Sub Checked_OnClick(sender As Object, e As System.EventArgs)
    Dim mmiItem As MyMenuItem = DirectCast(sender, MyMenuItem)

    MsgBox(CStr(mmiItem.ContactID))

    ' You can use the mmiItem.ContactID property
    ' for whatever you need

End Sub

--
==============================================
Happy to Help,
Tom Spink

http://dotnetx.betasafe.com > .NET code (soon)

One Day,

Quote:
> Hi,

> I have a context Menu that I am adding to via code. The items are all
added
> fine to my contextmenu

> CtxContactArray.MenuItems.Add(Trim(ContactName), New
> System.EventHandler(AddressOf Me.Checked_OnClick))

> The number of items I am adding to the context menu always changes, as its
a
> list of contacts selected a sql table(select id, ContactName from tbl).
What

> I want to do is do be able to get the contact_ID of the contact the user
has
> selected. The above menuitems.add code add in all the contactname all very
> nice, and no matter what name I select from the context menu, the
protected
> sub Checked_onClick is called.

> My Problem is that within the the sub Checked_OnClick, I actually need to
> use the ID value, not the name.

> How should I do this one....

> Thanks All



Wed, 21 Sep 2005 23:47:59 GMT  
 Progamming manually a Context Menu Items
Hope Tom had solved your problem.

In your post, you said in the sub Checked_OnClick you may get the "name".
Is this the name of the object which invoked Checked_OnClick?
'Cause I need to know which menuitem user has selected.
Would you please tell me how to know the name of object  which
runs this Checked_OnClick?

Thank you.



Quote:
> Hi,

> I have a context Menu that I am adding to via code. The items are all
added
> fine to my contextmenu

> CtxContactArray.MenuItems.Add(Trim(ContactName), New
> System.EventHandler(AddressOf Me.Checked_OnClick))

> The number of items I am adding to the context menu always changes, as its
a
> list of contacts selected a sql table(select id, ContactName from tbl).
What

> I want to do is do be able to get the contact_ID of the contact the user
has
> selected. The above menuitems.add code add in all the contactname all very
> nice, and no matter what name I select from the context menu, the
protected
> sub Checked_onClick is called.

> My Problem is that within the the sub Checked_OnClick, I actually need to
> use the ID value, not the name.

> How should I do this one....

> Thanks All



Fri, 23 Sep 2005 16:18:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Context Menu Handlers disables standard menu items

2. Disable context menu or close context menu

3. Context Menu items for COM Addins

4. Adding controls/items to the context menu

5. Shortcut (context) menu Item

6. Context menus for outlook items

7. Adding Items to Context Menus -- Possible?

8. Merging System Context Menu Item

9. Adding Events to context menu items

10. Default Bold Context Menu Items

11. How to add item to Context Menu in IE7 Options

12. adding items to a control's standard context menu

 

 
Powered by phpBB® Forum Software