Results 1 to 6 of 6

Thread: ContextMenu Click event problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    Uppsala, Sweden
    Posts
    20

    Question ContextMenu Click event problem

    I am trying to build a cool menu inside my program. I am building a schedule program where the user is to choose customer, my thought is to let the user enter a form with 5 text boxes. If it is a new customer he just types the info in ther, but it it is a returning customer I wan´t to have a contextmenu accesible throu right clicking inside the form. I have got so far that I load all the menu items from a database but here comes the problem. How can I determine witch item was clicked. Since you have to specify each Click event for every menuitem. I cant figure out how to do this in code. VB won´t let me add subs in a loop from a dataset. Is there a way to get the text property in the click event if you get what i mean.. Then i can check against the database ang fetch the right data.

    Regards
    Henrik

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You can have one method handle all the click events. Then you just look at the item clicked to determine what was clicked.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    Uppsala, Sweden
    Posts
    20
    Being new to this, how do I do that. All I get is sender and e in the Sub.

    /Henrik

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    If you cast the sender object to a menuitem object, you will have access to its properties. I think the menuitem has a text property you can access that would tell you which one it was. Also, if you named them as you add them to the menu, you could look at the name property.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    Uppsala, Sweden
    Posts
    20
    Sorry if I am a bit slow but I dont get the "cast the sender object to a menuitem object" part. Can you show me in code how that is done? This is my OnClick event.

    Protected Sub menuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


    End Sub

    /henrik

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Hmm , do you mean this :
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width