Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

rightclicking in a list box

Posted on 2006-11-13
10
Medium Priority
?
285 Views
Last Modified: 2010-04-16
I have a MS Word 2003 form, and in it a list box. I would like to be able to rightclick in this list box to paste a value, but as it is right now, rightclicking does not produce a usual menu, so I have to use "ctrl-v" to paste. Is there way to get the functionality I am looking for? Thanks.
0
Comment
Question by:MorDeRor
  • 4
  • 3
  • 3
10 Comments
 
LVL 2

Expert Comment

by:jay_s5
ID: 17934825
You can probably use Visual Basic for Applications (VBA) to capture the MouseUp event (fires when the mouse button is released) for the control you want to change.

I don't have Word 2003. My version of Word doesn't allow the Paste method to a variable or to a list box, but it does allow it with a text box and other controls. So, to use this solution you just add a text box to your user form and set it's visible property to 'false'. For the sake of the example below, call it TextBox1.

In the code for the control's MouseUp event, you would add the code to set the text value of TextBox1 to the contents of the clipboard, and then add the text value of TextBox1 as an item in your ListBox (ListBox1 in the example) using the AddItem method of the ListBox control.

An example follows:

Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
   
    'Set the value of TextBox1 to the contents of the Clipboard
    TextBox1.Paste
   
    If Button = 2 Then
        ListBox1.AddItem TextBox1.Text
    End If

End Sub

Of course, you can add error-capturing code and get fancy with sorting the contents of your ListBox in the same event if you want. You can also use the variables that the MouseUp event includes (the scary-looking stuff in the parentheses following the name of the event) to fine-tune the behavior you want.
0
 
LVL 3

Author Comment

by:MorDeRor
ID: 17936013
Are you saying that there is no simple way to just get the right click menu that is available just about everywhere else in windows?
0
 
LVL 1

Expert Comment

by:RupaliV
ID: 17936592
Hi,

try with this sample code

Clipboard.GetText will contain the data you have copied and when you right click on List box it will copy the data to list box.

Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then List1.AddItem Clipboard.GetText

End Sub
0
Technology Partners: 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!

 
LVL 1

Expert Comment

by:RupaliV
ID: 17984958
Hi,

  did you tried with the given code? Is it ok? Do let me know.
0
 
LVL 3

Author Comment

by:MorDeRor
ID: 17984997
No,

It wasn't that I just wanted to paste into a list box with a right click, rather I wanted to know if there was a way to get the right click menu in the list box. does that make sense?
0
 
LVL 2

Expert Comment

by:jay_s5
ID: 17989859
It seems like it should be easier to get the right-click menu, but as far as I can tell, your only option if you want a right-click pop-up menu within the list box is to create one yourself. It doesn't seem like my version of Word offers the right-click menu in a list box because none of the typical commands would apply to it.

You could create a form with the options you want on it and have VBA display it when you right-click the list box. That's about the only way I can see to do it.
0
 
LVL 1

Expert Comment

by:RupaliV
ID: 18005886
To popup a menu when you right click on the list box,
1. Create a menu using menu editor at design time with the main menu having visible property as False and the sub menu you want as visible property True.

2. Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Button = vbRightButton Then
          PopupMenu (Name of the menu)
      End If
End Sub

3. Private Sub mnuPaste_Click()
      List1.AddItem Clipboard.GetText
   End Sub


I hope this is what you want.
0
 
LVL 1

Expert Comment

by:RupaliV
ID: 18290148
Hi,

   Is the given sample code useful? Please let me know if its working.
0
 
LVL 3

Author Comment

by:MorDeRor
ID: 18294908
Hi, RupaliV,

sorry I've been away from this problem. Thanks for checking back. I am not sure that I understood your solution. how do I accomplish the first step? I don't think I know of a menu editor in VBA
0
 
LVL 2

Accepted Solution

by:
jay_s5 earned 2000 total points
ID: 18295193
I think RupalIV is talking about VB, where there is a menu editor and a PopupMenu method. I don't think you have that option in Word/VBA, unfortunately.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

927 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