Solved

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

Posted on 2002-03-05
18
611 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
  • 7
  • 6
  • 3
  • +2
18 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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
Comment Utility
This code assumesthat you created a menu called mnuEdit with all the entries.
0
 

Author Comment

by:mfarid2
Comment Utility
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
 
LVL 49

Expert Comment

by:Ryan Chong
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:mfarid2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks everyone for your answers. sweetpillow, your answer was most helpful.
0
 

Expert Comment

by:sweetpillow
Comment Utility
Hi mfarid2,

   Glad that I can help u...

Cheers,
Sweetpillow :)

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Share codes 68 114
Mysql vs Oracle 10 119
VBA open file from excel cell 4 33
JSON Response and request in VB6 application 11 132
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now