|
Post by chrissi75 on Jul 12, 2018 14:10:26 GMT
Hello,
is there a way to select more than one item of a Listbox?
~Chris
|
|
|
Post by tsh73 on Jul 12, 2018 20:22:58 GMT
I'm afraid it's plain not possible with JB.
|
|
|
Post by tsh73 on Jul 12, 2018 21:17:05 GMT
But it could be faked with graphicbox - it might be enough depending on the task Here the start
'attempt at faked multiselect list 'nomainwin items$ = "black, blue, brown, buttonface, cyan, darkblue, darkcyan, darkgray, darkgreen, darkpink, darkred, green, lightgray, palegray, pink, red, white, yellow" item$="*" while 1 i=i+1 item$=trim$(word$(items$, i, ",")) if item$="" then N=i-1: exit while print i, item$ wend print print N
open "faked multiselect listbox" for graphics as #gr #gr "trapclose [quit]" #gr "down" #gr "when leftButtonDown [click]" #gr "when characterInput [key]" #gr "place 0 0" #gr "\ " #gr "posxy dummy stringH"
sel$ = "1"+space$(N-1) print "Selected: >";sel$;"<" gosub [draw]
wait
[draw] #gr "cls" #gr "place 0 0" #gr "\ " for i = 1 to N item$=trim$(word$(items$, i, ",")) if mid$(sel$,i,1) ="1" then col$="cyan" else col$="white" #gr "backcolor ";col$ #gr "\ ";item$ next
#gr "flush"
return
[click] y = int(MouseY/stringH)+1 print y 'simple click 'toggle Y-th pos in sel$ oldSel$=sel$ sel$="" for i = 1 to N c$=mid$(oldSel$,i,1) if i = y then if mid$(oldSel$,i,1)="1" then c$=" " else c$="1" end if sel$=sel$+c$ next print "Selected: >";sel$;"<" gosub [draw] wait
[key] 'shift for range selection wait
[quit] print print "-- selected items: --" for i = 1 to N if mid$(sel$,i,1)="1" then print trim$(word$(items$, i, ",")) next print "---------------------" close #gr end
|
|
|
Post by Rod on Jul 13, 2018 6:38:04 GMT
The question is how would the user action the request? So multiple selections randomly or sequentially from a single list box? How do we know it’s done? How to correct selections etc etc.
I have answered this before with a solution that used two listboxes, one to select from and another showing the selection. You could click on a selected item in the selected listbox to send it back to the selection listbox. You also need a button for the user to say the selection is complete.
I will look for the code.
|
|
|
Post by Rod on Jul 13, 2018 7:48:22 GMT
This code lets a user select from one list to another. If you want a real multiselect listbox you will need to use Liberty BASIC and Stylebits. There is a tutorial on the LBPE that includes a multiselect example.
nomainwin dim options$(100) dim choices$(100) choicepointer=1 index=0 options$(0) = "First" options$(1) = "Second" options$(2) = "Third" options$(3) = "Fourth" options$(4) = "Fifth"
listbox #status.list, options$(), [selectionMade], 5, 35, 200, 90 listbox #status.choice, choices$(), [orderMove], 205, 35, 220, 90 button #status, "Done", [selectionDone], UL, 5, 5 button #status, "Delete", [selectionDelete], Ur, 15, 5 WindowWidth = 440 : WindowHeight = 300 open "Select and order tracks" for window as #status wait
[selectionMade] print #status.list, "selection? selection$" choices$(choicepointer)=selection$ print #status.choice, "Reload" choicepointer=choicepointer+1 wait
[orderMove] if movefrom=0 then print #status.choice, "selectionindex? movefrom" print #status.choice, "selection? selection$" else print #status.choice, "selectionindex? moveto" if moveto < movefrom then for n = movefrom to moveto step-1 choices$(n)=choices$(n-1) next choices$(moveto)=selection$ selection$="" movefrom=0 moveto=0 end if if moveto > movefrom then for n = movefrom to moveto choices$(n)=choices$(n+1) next choices$(moveto)=selection$ selection$="" movefrom=0 moveto=0 end if print #status.choice, "Reload" end if wait
[selectionDelete] if movefrom > 0 then for n=movefrom to choicepointer-1 choices$(n)=choices$(n+1) next choicepointer=choicepointer-1 selection$="" movefrom=0 moveto=0 print #status.choice, "Reload" end if wait
[selectionDone] close #status end
|
|
|
Post by tsh73 on Jul 13, 2018 20:49:55 GMT
Added code to make Range-click It happens that holding SHIFT blocks mouse events( ) so I did it with CTRL. So then CTRL pressed selection is made from previous click to Ctrl-Click Previous click point not reset so you can CtrlClick again changing last point. All selections outside range are cleared. 'attempt at faked multiselect list 'nomainwin items$ = "black, blue, brown, buttonface, cyan, darkblue, darkcyan, darkgray, darkgreen, darkpink, darkred, green, lightgray, palegray, pink, red, white, yellow" item$="*" while 1 i=i+1 item$=trim$(word$(items$, i, ",")) if item$="" then N=i-1: exit while print i, item$ wend print print N
open "faked multiselect listbox" for graphics as #gr #gr "trapclose [quit]" #gr "down" #gr "when leftButtonDown [click]" #gr "when characterInput [key]" #gr "place 0 0" #gr "\ " #gr "posxy dummy stringH"
sel$ = "1"+space$(N-1) y = 1 print "Selected: >";sel$;"<" gosub [draw]
wait
[draw] #gr "cls" #gr "place 0 0" #gr "\ " for i = 1 to N item$=trim$(word$(items$, i, ",")) if mid$(sel$,i,1) ="1" then col$="cyan" else col$="white" #gr "backcolor ";col$ #gr "\ ";item$ next
#gr "flush"
return
[click] y = int(MouseY/stringH)+1 'print y if CtrlDown=0 then 'simple click 'toggle Y-th pos in sel$ oldSel$=sel$ sel$="" for i = 1 to N c$=mid$(oldSel$,i,1) if i = y then if mid$(oldSel$,i,1)="1" then c$=" " else c$="1" end if sel$=sel$+c$ next lastClickY=y else 'select from lastClickY to y, including y1=lastClickY:y2=y if y1>y2 then tmp=y1:y1=y2:y2=tmp oldSel$=sel$ sel$="" for i = 1 to N 'c$=mid$(oldSel$,i,1) c$=" " 'so all out of range are reset if (y1<=i) and (i<=y2) then c$="1" end if sel$=sel$+c$ next end if print "Selected: >";sel$;"<" gosub [draw] wait
[key] 'shift for range selection key$ = Inkey$ 'It seems that holding SHIFT blocks mouse events 'So we go for CTRL instead k1=len(key$): k2=asc(key$): k3=asc(mid$(key$,2)) if k1=2 and k3= _VK_CONTROL then CtrlDown=0 if k2 and 8 then CtrlDown=1 end if 'print k1, k2, k3, CtrlDown wait
[quit] print print "-- selected items: --" for i = 1 to N if mid$(sel$,i,1)="1" then print trim$(word$(items$, i, ",")) next print "---------------------" close #gr end
key$ = Inkey$ if len(key$) = 1 then notice key$+" was pressed!" else keyValue = asc(right$(key$, 1)) if keyValue = _VK_SHIFT then END IF end if
|
|
|
Post by tsh73 on Jul 13, 2018 21:13:54 GMT
Re: Not quite I found old post of mine from 2012 saying
As you might know, Shift and Ctrl are the only buttons that could be checked for key Up event (with JB). (well, actually Alt is supposed too, but it was not reliable for me). So, here's the code that checks state of these buttons then you click a mouse.
The only disappointing thing is that then you hold SHIFT, left mouse click does not fire. All other combinatins: Ctrl-Left button
Ctrl-Right button Shift-Right button Ctrl-Shift-Right button
Ctrl-Middle button Shift-Middle button Ctrl-Shift-Middle button
are registered OK.
|
|