Results 1 to 14 of 14

Thread: menu on right click

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Brugge
    Posts
    102

    menu on right click

    if i right-click on a flexgrid i want to display a menu under the cursor.
    How to fix this
    Greetz Matje

  2. #2
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411

    here u go..

    here u go, i created this in like 1 min...
    Attached Files Attached Files
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Brugge
    Posts
    102
    thanks
    Greetz Matje

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Brugge
    Posts
    102
    And how to add menu items (in the right click menu) dynamically in the form in which the grid is?
    Greetz Matje

  5. #5
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    Do u mean u want to add more menu's at runtime ?? You will have to use the API for that.
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Brugge
    Posts
    102
    yes
    now there is only flexgrid popup in the menu.
    But i want to add more items like this on it.

    If i have to use the API. could you please tell me how to use it.

    thanks in advance
    Greetz Matje

  7. #7
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    uhh just add them thru mnu editor in the frmpopup form.
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Brugge
    Posts
    102
    is there no way to do it a design time
    Greetz Matje

  9. #9
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    Ok if you add a menu thru the menueditor that is at designtime. If you want to add menu items after your program is compiled then this is adding at runtime. If you open the frmpopup form and goto tools/menueditor, u will see the popup items. u may add more popups there. if u want to add to it after your program is compiled, search on the forums theres plenty of examples
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Brugge
    Posts
    102
    next problem

    when i right click on a row and another row was selected before i'm rightclicking on the row that was selected and not on the one where my cursor was
    Greetz Matje

  11. #11
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    your gonna have to retype that last message, i don't understand that at ALL, LOL
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Aug 2001
    Location
    Brugge
    Posts
    102
    So when i right click on the 3 th row
    and the 1st row was selected

    and i ask for the row and col value.
    then i get row 1 instead of the 3 th
    Greetz Matje

  13. #13
    Hyperactive Member AAG's Avatar
    Join Date
    Aug 2000
    Location
    United States
    Posts
    411
    ooh ok i get u now. What you can do is use the Mouse_Event API to send a mouseclick to the flexgrid before popping up the menu at point where the right click event happened then right after that put the code to popup the menu. Try this example below.


    Add The Below To Your Declarations In Your Form
    VB Code:
    1. Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    2. Private Declare Function SetCursorPos Lib "user32.dll" (ByVal X As Long, ByVal Y As Long) As Long
    3.  
    4. Private Const MOUSEEVENTF_LEFTDOWN = &H2
    5. Private Const MOUSEEVENTF_LEFTUP = &H4
    6.  
    7. Private Const MOUSEEVENTF_RIGHTDOWN = &H8
    8. Private Const MOUSEEVENTF_RIGHTUP = &H10

    then delete whatever code you have in the Mouse_Down even of the flexgrid and add this bit of code to the Mouse_Down event of the flexgrid.

    [Highlight=VB]
    If Button = 2 Then
    DoEvents
    Call mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0)
    Call mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0)
    DoEvents
    frmpopup.PopupMenu frmpopup.mnupopup
    End If
    [Highlight=VB]

    there you go, all this does is sends a left click before the menu pops up. I don't know if this is the right way to do it, but it works.
    This Business Is Binary. Your a 1 or a 0. Alive or Dead. (AntiTrust)

  14. #14
    Junior Member
    Join Date
    Sep 2001
    Location
    Pittsburgh
    Posts
    23
    There is an easier way, I found after a lot of searching...

    VB Code:
    1. Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     If Button = vbRightButton Then
    3.         MSFlexGrid1.Row = MSFlexGrid1.MouseRow
    4.         MSFlexGrid1.Col = MSFlexGrid1.MouseCol
    5.         ' run whatever code you have
    6.     End If
    7. End Sub
    Why they can't just use .RowContaining and .ColContaining like all the other grids is beyond me.

    Tom

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