Main Board > Language

Update a LIST_BOX

(1/2) > >>

edjack:
what is the command to update the currently selected item in a LIST_BOX with a new value?

jasonc:
Ed,
You have to remove the currently selected item, add your new item, then select it.  See lines 52-58 below

0010 print 'CS'; list
0020 list_box 100,@(2,14,12,6),fnt="*"
0030 list_box load 100,"Dog/Cat/Pig/"; wait 1
0040 list_box write 100,"Cat"; wait 1
0050 ! list_box load 100,1,*
0052 list_box read 100,_index ! Get index of current selection
0054 list_box load 100,_index,* ! Remove current selection
0056 list_box load 100,_index,"T-Rex" ! Add this one in its place
0058 list_box write 100,"T-Rex" ! Select the new option
0060 end

James Zukowski:
Here's a variation on that theme, without having to actually remove the existing item:


--- Code: ---0010 print 'CS'; list
0020 My_List=100
0030 list_box My_List,@(2,14,12,6),fnt="*"
0040 list_box load My_List,"Dog/Cat/Pig/"; wait 1
0050 My_List'FindItemText$="Cat" ! Locate the item to change
0060 My_List'ItemText$="T-Rex" ! Load this one in its place
0070 wait 3
0080 ! list_box remove My_List
0090 end

--- End code ---

Mike King:
Actually its easier than that -- just set 'Item to the index for the item you want to change then set 'ItemText$ to the new value.

If you want to change the current item the set 'Item to 'CurrentItem and then change 'ItemText$. Here is a demo program.

--- Code: ---0010 PRINT 'CS'; LIST
0020 LET Lb=100
0030 LIST_BOX Lb,@(40,1,12,6),FNT="*"
0040 LIST_BOX LOAD Lb,"Dog/Cat/Pig/Cow/Ant/Gnu/"
0050 WHILE 1
0060 SET_FOCUS Lb
0070 INPUT *
0080 IF CTL=4 THEN BREAK
0090 LET item=lb'currentItem
0100 IF item=0 OR CTL<1 OR CTL>3 THEN CONTINUE
0110 IF CTL=1 THEN LET Lb'item=item; LET Lb'ItemText$=UCS(Lb'ItemText$)
0120 IF CTL=2 THEN LET Lb'item=item; LET Lb'ItemText$=LCS(Lb'ItemText$)
0130 IF CTL=3 THEN LET Lb'item=item; LET Lb'ItemText$=CVS(Lb'ItemText$,256)
0140 WEND
0150 ! list_box remove Lb
0160 END
--- End code ---
Run it and select an item from the list.  Pressing F1 will convert to upper, F2 lower, F3 mixed, F4 Quit

edjack:

--- Quote from: jasonc on July 25, 2018, 11:21:13 AM ---Ed,
You have to remove the currently selected item, add your new item, then select it.  See lines 52-58 below

0010 print 'CS'; list
0020 list_box 100,@(2,14,12,6),fnt="*"
0030 list_box load 100,"Dog/Cat/Pig/"; wait 1
0040 list_box write 100,"Cat"; wait 1
0050 ! list_box load 100,1,*
0052 list_box read 100,_index ! Get index of current selection
0054 list_box load 100,_index,* ! Remove current selection
0056 list_box load 100,_index,"T-Rex" ! Add this one in its place
0058 list_box write 100,"T-Rex" ! Select the new option
0060 end

--- End quote ---

This is what i needed.

Navigation

[0] Message Index

[#] Next page

Go to full version