
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