|
-
Jun 26th, 2001, 09:26 PM
#1
Thread Starter
Hyperactive Member
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]
-
Jun 26th, 2001, 10:11 PM
#2
In a Module:
VB Code:
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
Private Const LB_GETCOUNT = &H18B
Private Const LB_GETTEXT = &H189
Private Const LB_GETTEXTLEN = &H18A
Public Function GetListBoxItems(ByVal hWnd As Long) As String
Dim lCount As Long, lIndex As Long
Dim sItem As String, lLen As Long
Dim sList As String
' Find the no. of items in the listbox
lCount = SendMessage(hWnd, LB_GETCOUNT, 0&, ByVal 0&)
' Enumerate the items
For lIndex = 0 To lCount - 1
' Get the length of the Item Text
lLen = SendMessage(hWnd, LB_GETTEXTLEN, lIndex, ByVal 0&)
' Create a buffer of the specified length
sItem = Space(lLen)
' Extract the Item Text into the buffer
Call SendMessage(hWnd, LB_GETTEXT, lIndex, ByVal sItem)
' Add it to the string
sList = sList & vbCrLf & sItem
Next
' Return the string minus the first preceeding CRLF
GetListBoxItems = Mid(sList, 3)
End Function
Example Usage:
VB Code:
Private Sub Form_Load()
Dim lIndex As Long
For lIndex = 1 To 10
List1.AddItem "Item " & lIndex
Next
End Sub
Private Sub Command1_Click()
' Using Local Listbox for example, but could pass the Handle of any external Listbox
Text1 = GetListBoxItems(List1.hWnd)
End Sub
-
Jun 26th, 2001, 10:31 PM
#3
Hyperactive Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|