Right+Clicking to get a pop-up menu on a MSFlexGrid control

I have a form with a MSFlexGrid control on it. When I click on the header of a column, the column is highlighted. What I would like to do is to be able to right-click on the column and come up with a pop-up menu with Undo/Cut/Copy/Paste/Delete/Select All. I would like to have the exact same menu as when we right-click on a textbox.
How do I do this?
mfarid2Asked:
Who is Participating?
 
sweetpillowConnect With a Mentor Commented:
Hi mfarid2,

   Actually I've do the same thing like what u would like to do now. I'm using a MDIForm as well and I add the popup menu at the menu editor in MDIForm like what I mention b4. Then I have the MDIChildForm and in this childForm I have a picture file.
   So I put the following coding so that when user right click on the picture1 the poppup menu will appear :
Private Sub picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then   'right click
   MDIMain.mnuPUPaste.Visible = True      
   MDIMain.mnuPUCopy.Visible = True
   MDIMain.mnuPUCut.Visible = True
   PopupMenu MDIMain.mnuPUForm  
End If
End Sub

Have u try this coding ?? It really works ! Tell me if u have try this coding but u still cannot see the popup menu. Once u have the popup menu, u may need to write some code in MDIMain in order for the copy action to be done. Maybe when u right click the Flexgrid u need to select the column and copy the data in it. So that when u paste the data will be correct.

Private Sub mnuPUCopy_Click()
 'put your copy coding here
End Sub

   Regarding run time create the menu object, I do not sure whether it'll be works or not. But I've try b4 and it doesn't work. Maybe my method is wrong.

By the way, Richie I cannot access the link u provide :
http://www.programando.com/visualbasic/crazy/API/API63.htm

cheers,
sweetpillow :)
0
 
Richie_SimonettiIT OperationsCommented:
maybe this:

Private Sub MSFlexGrid1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 2 Then
Me.PopupMenu mnuEdit
End If
End Sub
0
 
Richie_SimonettiIT OperationsCommented:
This code assumesthat you created a menu called mnuEdit with all the entries.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
mfarid2Author Commented:
Thank you Richie for your answer. However, this is the easy part. My biggest problem is how do I create mnuPop the way I want. That is, when on a text box control, you Right+Click, you get the menu, then you can click Copy. That copies the stuff in the text box to the clipboard. That is exactly the functionality I want to implement with mnuPop.
0
 
Ryan ChongCommented:
How would you like to "Copy" the textbox value? Is it the textboxes is dynamic (no only limit to 1 textbox)?

You can copy the content of the TextBox to Clipboad like this:

In your CopyContent menu, add:

Clipboard.SetText Text1.Text ' Put text on Clipboard.

and

Temp = Clipboard.GetText(CF_TEXT)   ' Get Clipboard text

to paste the clipboard content..
0
 
sweetpillowCommented:
Hi mfarid2,

   First of all in the Form menu editor, u need to do this at the last line :
Form Popup
...Cut
...Copy
...Paste

Properties for Form Popup : Caption:Form Popup, Name:mnuPUForm,uncheck Visible
Properties for Cut : Caption:Cut, Name:mnuPUCut
Properties for Copy : Caption:Copy, Name:mnuPUCopy
Properties for Paste : Caption:Paste, Name:mnuPUPaste

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Button = vbRightButton Then   'right click
     MDIMain.mnuPUPaste.Visible = True      
     MDIMain.mnuPUCopy.Visible = True
     MDIMain.mnuPUCut.Visible = True
     PopupMenu Form.mnuPUForm  
  End If
End Sub

Private Sub mnuPUCut_Click()
  'put your cut coding here
End Sub

Cheers,
Sweetpillow :)
0
 
sweetpillowCommented:
Hi mfarid2,

   To guide u more u can take a look at this sample code..I believe this will help u a lot.
http://vb-helper.com/howtoint.htm
There is a link called : Change a popup menu's items at run time (3K) and Add pictures to a popup menu (4K).

Cheers,
Sweetpillow :)
0
 
Richie_SimonettiIT OperationsCommented:
Nice, nice but question was how to show popup menu and not how to implement its submenus.
So, first of all, what do you need to copy, paste cut,undo and select all?, entire column?, first cell?, other?, "form caption"?, your ssn?, what?
in the meantime, you could see this:
http://www.programando.com/visualbasic/crazy/API/API63.htm
0
 
sweetpillowCommented:
Hi,
  The way to show the popup menu I already posted in the previous comment. The site I suggest is a popup menu sample with extra features to implement it. I'm sure the program did create the popup menu before they add any features to it ! From there u can get some idea to create your own popup menu.
0
 
sweetpillowCommented:
Hi mFarid2,

  Some correction here. Since u want to right click the MSFlexGrid and popup menu will appear then u need to do this at MSFlexGrid_MouseDown instead of Form_MouseDown :

Private Sub MSFlexGrid_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
 If Button = vbRightButton Then   'right click
    MDIMain.mnuPUPaste.Visible = True      
    MDIMain.mnuPUCopy.Visible = True
    MDIMain.mnuPUCut.Visible = True
    PopupMenu Form.mnuPUForm  
 End If
End Sub

cheers,
sweetpillow.
0
 
mfarid2Author Commented:
To everyone, thanks for your responses. Actually, what I am trying to do is:
1) Create a run-time menu object with Copy feature when user right clicks
2) Copy the data in the column on the MSFlexgrid on which user right clicked to the Clipboard
3) Destroy the menu object

The reason I need to create a run-time menu object and not a menu control by using the Menu Editor is because my main form in my application is a MDI parent form and the form I am trying to do the right click on is a MDI child form. When I create a menu by using the Menu Editor in the MDI child form, the parent form's menu disappears and that's NOT what I want.

Anyway, this may NOT be doable. However, if anybody wants any clarifications, I can explain further.

0
 
Richie_SimonettiIT OperationsCommented:
First of all, this example hiddes the menu Edition from all places in application and it is only used as a popup.
Did you try it?
0
 
Richie_SimonettiIT OperationsCommented:
You could use:
Private Sub FG_SelChange()
Clipboard.SetText FG.Clip, vbCFRTF
End Sub
to put contents of selected colum in clipboard.
FG is a short for Msflex....
Hope it helps
Why do you continue using Datacontrol?

0
 
Richie_SimonettiIT OperationsCommented:
It appears that site is no longer available.
Here is the code from it:
Creación de la opción Edición en nuestro programa

--------------------------------------------------------------------------------

Este código implementa las opciones que comunmente se muestran en el menu Edición. Deshacer, Cortar, Copiar, Pegar y Eliminar usando SendMessage.

Este ejemplo es valido para 16 y 32 bits.

En el formulario:

Private Sub mnuDeshacer_Click()
    'Esto es para Deshacer
    EditPerform WM_UNDO
End Sub

Private Sub MnuCortar_Click()
    'Esto para cortar un area seleccionada
    EditPerform WM_CUT
End Sub

Private Sub MnuCopiar_Click()
    'Esto para Copiar una selección al ClipBoard
    EditPerform WM_COPY
End Sub

Private Sub MnuPegar_Click()
    'Esto para pegar lo que esta en el Clipboard guardado
    EditPerform WM_PASTE
End Sub

Private Sub mnuEliminar_Click()
    'Esto para eliminar la selección
    EditPerform WM_CLEAR
End Sub

Private Sub EditPerform(EditFunction As Integer)
    'Y esta es la rutina que hace todo...
    If TypeOf Me.ActiveControl Is TextBox Then
        Call SendMessage(Me.ActiveControl.hwnd, EditFunction, 0, 0&)
    ElseIf TypeOf Me.ActiveControl Is XEditor Then
        If m_ControlKey = False Then
           Call SendMessage(Me.ActiveControl.hwnd, EditFunction, 0, 0&)
        End If
    End If
End Sub
En un módulo:

Option Explicit
'Api Para Cortar, Copiar, Pegar ,Etc.

#If Win16 Then
   Private Declare Function SendMessage Lib "User" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
#ElseIf Win32 Then
   Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
#End If

Const WM_CUT = &H300
Const WM_COPY = &H301
Const WM_PASTE = &H302
Const WM_CLEAR = &H303
Const WM_UNDO = &H304
#If Win16 Then
   Const EM_CANUNDO = &H416
   Const EM_GETMODIFY = &H408
#ElseIf Win32 Then
   Const EM_CANUNDO = &HC6
   Const EM_GETMODIFY = &HB8
#End If
Private m_ControlKey As Boolean
Fecha: 28/09/99
0
 
Richie_SimonettiIT OperationsCommented:
If what you need is a Excel "clone" you will be in trouble.
If you need that funcionality, could you use excel itself by Automation?.
It easy to put entire excel app inside your form with SetParent API.
0
 
MoondancerCommented:
THIS IS ADDED TO ALL YOUR OPEN QUESTIONS TODAY.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20273585.html
http://www.experts-exchange.com/questions/Q.20247001.html
http://www.experts-exchange.com/questions/Q.20272401.html


Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
mfarid2Author Commented:
Thanks everyone for your answers. sweetpillow, your answer was most helpful.
0
 
sweetpillowCommented:
Hi mfarid2,

   Glad that I can help u...

Cheers,
Sweetpillow :)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.