CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2002
    Location
    USA (all the way!!)
    Posts
    55

    Copy from list box

    A book I was looking at implied you could copy the information from a list box to the clipboard with code. Does anyone have a knowledge of this? Thanks for your time.


  2. #2
    Join Date
    Feb 2000
    Location
    Ireland
    Posts
    808

    Re: Copy from list box

    You could do something like this

    Dim Mystr as string
    for i = 0 to List1.ListCount - 1
    Mystr = Mystr & List1.List(i) & vbCrLf
    next
    Clipboard.Clear
    Clipboard.SetText Mystr





  3. #3
    Join Date
    Sep 2001
    Location
    IL, USA
    Posts
    1,090

    Re: Copy from list box


    'The code below clear Clipboard and copy selected items from a listbox to it.
    private Sub Command1_Click()
    Dim i, strToCopy as string, SelNum as Long
    strToCopy = ""
    SelNum = 0
    for i = 0 to List1.ListCount - 1
    If List1.Selected(i) then
    SelNum = SelNum + 1
    strToCopy = strToCopy & List1.List(i) & IIf(SelNum < List1.SelCount, vbCrLf, "")
    End If
    next
    Clipboard.Clear
    Clipboard.SetText strToCopy
    End Sub
    'The code below clear Clipboard and copy all items in a listbox to it.
    private Sub Command2_Click()
    Dim i as Long, strToCopy as string
    strToCopy = ""
    for i = 0 to List1.ListCount - 2
    strToCopy = strToCopy & List1.List(i) & vbCrLf
    next
    strToCopy = strToCopy & List1.List(i)
    Clipboard.Clear
    Clipboard.SetText strToCopy
    End Sub


    Help us improve our answers by rating them.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured