CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    Right Click Menu.............

    Any ideas on creating a right click menu (like a pop-up) to delete data from a flexgrid ?




  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Right Click Menu.............

    Create the Menu using the Menu Editor and set its Visible Property to False, then call it using:

    PopupMenu MenuName

    Example:
    Create a menu called mnuFlexPopup, set its Visible Property to False, create a Sub Menu Item Called mnuClearCell, then paste this code:

    private Sub Form_Load()
    Dim iX as Integer
    Dim iY as Integer

    'Generate some Dummy Data
    With MSFlexGrid1
    .FixedCols = 0
    .FixedRows = 0
    .Rows = 5
    .Cols = 4
    for iY = 0 to .Rows - 1
    for iX = 0 to .Cols - 1
    .TextMatrix(iY, iX) = Rnd * 100
    next
    next
    End With
    End Sub

    private Sub mnuClearCell_Click()
    'Clear the Specified Cell
    With MSFlexGrid1
    .TextMatrix(.Tag, .RowData(.Tag)) = ""
    End With
    End Sub

    private Sub MSFlexGrid1_MouseUp(Button as Integer, Shift as Integer, x as Single, y as Single)
    With MSFlexGrid1
    'Verify Mouse is over a Row
    If .RowPos(.MouseRow) + .RowHeight(.MouseRow) > y then
    'Verify Mouse is over a Column
    If .ColPos(.MouseCol) + .ColWidth(.MouseCol) > x then
    If Button = vbRightButton then
    'Store the Row in the Tag property
    .Tag = .MouseRow
    'Store the Column in the Rows Data property
    .RowData(.MouseRow) = .MouseCol
    'Show the PopupMenu
    PopupMenu mnuFlexPopup
    End If
    End If
    End If
    End With
    End Sub





    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: Right Click Menu.............

    The idea that comes to my mind first would be, add a hidden menu on the form with the flexgrid on it. Then in the FlexGrid1_MouseDown event place the folowing code:

    private Sub FlexGrid1_MouseMove(Button as Integer, Shift as Integer, X as Long, Y as Long)
    If Button = vbRightButton then
    'select the row that was clicked in the grid

    'I personally don't work with the Flexgrid, so I'm not 100% sure that
    'the following line of code will work - but something similar to this
    'should be done.
    FlexGrid1.Row = FlexGrid1.RowContaining(X)

    'show the menu with the delete option etc...
    PopupMenu mnuRightClickMenu
    End If
    End Sub




    I hope this helps,
    John


    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  4. #4
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    Re: Right Click Menu.............

    How do you create a Sub Menu item ?


  5. #5
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Right Click Menu.............

    After Entering in your Main Menu Item and Click Next in the MenuEditor, click the Right Arrow, to Indent the Next Entry, creating a SubMenu Item of that Menu Item, so that the List in the Menu Editor Looks like this:

    File
    .. Clear Cell



    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  6. #6
    Join Date
    Dec 1999
    Location
    MD, USA
    Posts
    34

    Re: Right Click Menu.............

    Thanks ! ! !


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

Featured