To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Jun 26th, 2001, 09:26 PM   #1
Oafo
Hyperactive Member
 
Join Date: Feb 01
Posts: 421
Oafo is an unknown quantity at this point (<10)
LB_GETTEXT, does it work?

I've tried many times trying to get ALL the text from a ListBox. But nothing seems to work, I've tried searching through posts and stuff, but nobody seems to want what I need. How can I get all of the text from a ListBox, and put it in a TextBox? Example:

The ListBox looks like this:

Dog
Cat
Cow
Horse

and when you press a button, the TextBox looks like this:

Dog
Cat
Cow
Horse

Anyone know how to do this??
__________________
[vbcode]
' comment
Rem remark
[/vbcode]
Oafo is offline   Reply With Quote
Old Jun 26th, 2001, 10:11 PM   #2
Aaron Young
Guru
 
Aaron Young's Avatar
 
Join Date: Jun 99
Location: Red Wing, MN, USA
Posts: 2,170
Aaron Young has a spectacular aura about (150+)Aaron Young has a spectacular aura about (150+)
In a Module:
VB Code:
  1. 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
  2. Private Const LB_GETCOUNT = &H18B
  3. Private Const LB_GETTEXT = &H189
  4. Private Const LB_GETTEXTLEN = &H18A
  5. Public Function GetListBoxItems(ByVal hWnd As Long) As String
  6.     Dim lCount As Long, lIndex As Long
  7.     Dim sItem As String, lLen As Long
  8.     Dim sList As String
  9.    
  10.     ' Find the no. of items in the listbox
  11.     lCount = SendMessage(hWnd, LB_GETCOUNT, 0&, ByVal 0&)
  12.     ' Enumerate the items
  13.     For lIndex = 0 To lCount - 1
  14.         ' Get the length of the Item Text
  15.         lLen = SendMessage(hWnd, LB_GETTEXTLEN, lIndex, ByVal 0&)
  16.         ' Create a buffer of the specified length
  17.         sItem = Space(lLen)
  18.         ' Extract the Item Text into the buffer
  19.         Call SendMessage(hWnd, LB_GETTEXT, lIndex, ByVal sItem)
  20.         ' Add it to the string
  21.         sList = sList & vbCrLf & sItem
  22.     Next
  23.     ' Return the string minus the first preceeding CRLF
  24.     GetListBoxItems = Mid(sList, 3)
  25. End Function
Example Usage:
VB Code:
  1. Private Sub Form_Load()
  2.     Dim lIndex As Long
  3.     For lIndex = 1 To 10
  4.         List1.AddItem "Item " & lIndex
  5.     Next
  6. End Sub
  7. Private Sub Command1_Click()
  8.     ' Using Local Listbox for example, but could pass the Handle of any external Listbox
  9.     Text1 = GetListBoxItems(List1.hWnd)
  10. End Sub
__________________
Aaron Young
Red Wing Software, Inc.
Aaron Young is offline   Reply With Quote
Old Jun 26th, 2001, 10:31 PM   #3
Ed Lampman
Hyperactive Member
 
Ed Lampman's Avatar
 
Join Date: Mar 01
Posts: 273
Ed Lampman is an unknown quantity at this point (<10)
Private Sub Command1_Click()

Dim i as integer
Dim s as String

for i = 0 to List1.Listcount-1
s=s & List1.List(i) & vbNewLine
next

Text1.Text = s

end sub
Ed Lampman is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:04 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.