Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable Copy&Paste from a listbox

Status
Not open for further replies.

Dovalle

Programmer
Jul 13, 2002
1
IL
Hi,
I have a listbox and i want users to be able to use the regular way of copy&paste.
When doing ctrl+c and ctrl+v im getting garbage
Is there a way to do so?
Thanks
 
There could be an easier way to do this but this was my quick-fix for it (needs to be "cleaned up") :

Public CtrlCode

' Fill some list box with data
Private Sub CommandButton1_Click()
ListBox1.AddItem "Test1"
ListBox1.AddItem "Test2"
ListBox1.AddItem "Test3"
ListBox1.AddItem "Test4"
ListBox1.AddItem "Test5"
End Sub


Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

' Key_Down event traps only the first key in the Ctrl-C sequence (e.g. Ctrl). Use CtrlCode to flag that CTRL has been pressed while determining if the second key in sequence is "c" or "C".

' 17 is the key code for CTRL
If KeyCode = 17 Then CtrlCode = "Pressed"

End Sub

Private Sub ListBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

If CtrlCode = "Pressed" and KeyCode = 67 Then

Set MyData = New DataObject
MyData.SetText ListBox1.Text
' Copy data to clipboard
MyData.PutInClipboard
' Now that it is on clipboard, now able to
' paste "normally" using Ctrl-v.

End If

CtrlCode = "NotPressed"

End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top