Solved

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

Posted on 2002-03-05
18
697 Views
Last Modified: 2010-08-05
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?
0
Comment
Question by:mfarid2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 3
  • +2
18 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6842321
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6842324
This code assumesthat you created a menu called mnuEdit with all the entries.
0
 

Author Comment

by:mfarid2
ID: 6842569
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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6843094
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
 

Expert Comment

by:sweetpillow
ID: 6843105
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
 

Expert Comment

by:sweetpillow
ID: 6843140
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6844066
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
 

Expert Comment

by:sweetpillow
ID: 6845908
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
 

Expert Comment

by:sweetpillow
ID: 6845968
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
 

Author Comment

by:mfarid2
ID: 6847765
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6848426
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6848453
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
 

Accepted Solution

by:
sweetpillow earned 200 total points
ID: 6849025
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6850157
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6850159
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
 
LVL 1

Expert Comment

by:Moondancer
ID: 6858615
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
 

Author Comment

by:mfarid2
ID: 6861295
Thanks everyone for your answers. sweetpillow, your answer was most helpful.
0
 

Expert Comment

by:sweetpillow
ID: 6863123
Hi mfarid2,

   Glad that I can help u...

Cheers,
Sweetpillow :)

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question