Liberty BASIC Community Forum
« multi-select listbox »

Welcome Guest. Please Login or Register.
Jan 22nd, 2018, 6:08pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: multi-select listbox  (Read 140 times)
alincon2001
Guru
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 510
xx multi-select listbox
« Thread started on: Nov 27th, 2017, 8:55pm »

I am using a listbox with multi-select enabled:
Code:
 Stylebits #match.lbx1, _LBS_MULTIPLESEL or _LBS_SORT, _LBS_DISABLENOSCROLL, 0, 0
 


No problem entering more than one selection. I store the chosen items in a field with length equal to the number of items in the listbox. A chosen item is represented in the field by a '1', non-chosen by a '0'. Example '001010011' This works as planned.

But if I close the window containing the listbox, and later reopen it and want to show the choices previously made, my code executes but does not highlight any items in the list box.
Code:
        for m = 1 to len(z$)  'z$ contains the ones and zeros
            if mid$(z$,m,1) = "1" then                   
                #match.lbx1, "selectindex "; m
            end if
        next
 


r.m.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: multi-select listbox
« Reply #1 on: Nov 28th, 2017, 02:09am »

Some runnable code that shows the problem. Multline select seems to stop us updating a listbox selection programmatically.


Code:
nomainwin
z$(0) = "Cold Contact Phone Call"
z$(1) = "Send Literature"
z$(2) = "Follow Up Call"
z$(3) = "Send Promotional"
z$(4) = "Final Call"
Stylebits #status.list, _LBS_MULTIPLESEL or _LBS_SORT, _LBS_DISABLENOSCROLL, 0, 0
'Stylebits #status.list,  _LBS_EXTENDEDSEL or _LBS_SORT, _LBS_DISABLENOSCROLL, 0, 0


listbox #status.list, z$(), [quit], 5, 35, 250, 90
WindowWidth = 300 : WindowHeight = 180
open "Select options" for window as #status
z$="01010"

for m = 1 to len(z$)  'z$ contains the ones and zeros
            if mid$(z$,m,1) = "1" then
                #status.list "select ";z$(m-1)
            end if
        next
        wait

[quit]
close #status
end
 

« Last Edit: Nov 28th, 2017, 04:01am by Rod » User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5618
xx Re: multi-select listbox
« Reply #2 on: Nov 28th, 2017, 05:49am »

Ahh.. it was on the wiki all along. Mr Bill Beasley showed us how. You need to send a special message to the listbox to have it simply select an item. The Liberty commands find a string or index.

Code:
z$(0) = "Cold Contact Phone Call"
z$(1) = "Send Literature"
z$(2) = "Follow Up Call"
z$(3) = "Send Promotional"
z$(4) = "Final Call"
Stylebits #status.list, _LBS_MULTIPLESEL or _LBS_SORT, _LBS_DISABLENOSCROLL, 0, 0



listbox #status.list, z$(), [quit], 5, 35, 250, 90
WindowWidth = 300 : WindowHeight = 180
open "Select options" for window as #status
hLB = hwnd(#status.list)
z$="01010"

for m = 1 to len(z$)  'z$ contains the ones and zeros
            if mid$(z$,m,1) = "1" then
                null = SendMessageA(hLB, _LB_SETSEL, 1, m-1)
            end if
        next
        wait

[quit]
close #status
end

Function SendMessageA(hW, msg, par1, par2)
    CallDLL #user32, "SendMessageA",_
        hW as Ulong, _ 'Handle of the control (listbox)
        msg as Long, _ 'Stylebits (Windows Constant)
        par1 as Long, _ 'Parameter 1 (sometimes irrelevant)
        par2 as Long, _ 'Parameter 2 (sometimes irrelevant)
        SendMessageA as long 'Return Value, 1 = success
End Function

 
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls