PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Update a LIST_BOX  (Read 2298 times)

edjack

  • Silver Member
  • ***
  • Posts: 44
  • Computerease
    • View Profile
Update a LIST_BOX
« on: July 25, 2018, 10:47:30 AM »
what is the command to update the currently selected item in a LIST_BOX with a new value?
Ed Jack
Computerease

jasonc

  • Silver Member
  • ***
  • Posts: 22
    • View Profile
Re: Update a LIST_BOX
« Reply #1 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

James Zukowski

  • Diamond Member
  • *****
  • Posts: 296
    • View Profile
Re: Update a LIST_BOX
« Reply #2 on: July 25, 2018, 01:06:42 PM »
Here's a variation on that theme, without having to actually remove the existing item:

Code: [Select]
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
James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Mike King

  • Diamond Member
  • *****
  • Posts: 3810
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Update a LIST_BOX
« Reply #3 on: July 25, 2018, 01:21:41 PM »
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: [Select]
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
Run it and select an item from the list.  Pressing F1 will convert to upper, F2 lower, F3 mixed, F4 Quit

Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

edjack

  • Silver Member
  • ***
  • Posts: 44
  • Computerease
    • View Profile
Re: Update a LIST_BOX
« Reply #4 on: July 25, 2018, 01:29:10 PM »
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

This is what i needed.
Ed Jack
Computerease

edjack

  • Silver Member
  • ***
  • Posts: 44
  • Computerease
    • View Profile
Re: Update a LIST_BOX
« Reply #5 on: July 25, 2018, 01:30:03 PM »
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: [Select]
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
Run it and select an item from the list.  Pressing F1 will convert to upper, F2 lower, F3 mixed, F4 Quit
This works even better...
Ed Jack
Computerease