DirectuX
12-02-2020, 18:43
Ciao,
a listbox can have multi selection,
the gettext command only return the first selected line. How do you get the whole list of the selected items ?
Petr Schreiber
13-02-2020, 21:53
Hi DirectuX,
it is solution mostly by Win32API, but seems to work:
function GetSelectedListboxItems(hDlg as dword, hCtl as long, byref out_result() as string) as long
long selectionCount
long hList
control handle hDlg, hCtl to hList
selectionCount = SendMessage(hList, %LB_GETSELCOUNT, 0, 0)
if selectionCount > 0 then
long itemIndexes(selectionCount)
SendMessage(hList, %LB_GETSELITEMS, selectionCount, varptr(itemIndexes(1)))
' Fit the output array to selection count
redim out_result(selectionCount)
' Limited to 512 characters, feel free to adjust
dim singleTextItem as asciiz * 512
' Extract all items from ListBox
for i as long = 1 to selectionCount
SendMessage(hList, %LB_GETTEXT, itemIndexes(i), varptr(singleTextItem))
out_result(i) = singleTextItem
next
return selectionCount
end if
end function
You can use it like:
string items()
long selectedCount = GetSelectedListboxItems(hDlg, %myListBox, items)
if selectedCount then msgbox hDlg, join$(items, ",")
Petr
DirectuX
13-02-2020, 22:35
I didn't get used to sendmessage, now I better understand its meaning.
Before your sample, I thought there must have been a single command rather than a succession.
That was instructive to me, thanks Petr !