Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove listbox items one by one
#1
I want to remove listbox items one by one.
If the listbox has 3 items: a,b and c

Remove 'a', then output something, in mine example I just output "i"
wait 0.4 seconds
Remove 'b', then output "i"
wait 0.4 seconds
Remove 'c', then output "i"

The actual goal is to process (remove) each item in the listbox one by one and after it's processed  (removed) then execute some other function.
In stead of a function I have put an output "i" just to keep the example as simple as possible.

I attempted to run the subfunction in a seperate thread but it does not work like I described above
(What I want to see is an item removed from the listbox [pause] next item removed, the out "i" represents the placeholder for a function)

Function ListDialogRotate
Code:
Copy      Help
str- lb_items=
;item 1
;item 2
;item 3

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 296 148 "Dialog" "4"
;3 ListBox 0x54230101 0x200 0 0 296 114 ""
;4 Button 0x54032000 0x0 5 119 48 14 "START"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str lb3=
;a
;b
;c
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,,int amount
,,int i
,,int- id_lbmain;id_lbmain=3
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4
,,amount=LB_GetCount(id(id_lbmain hDlg))
,,for(i amount-1 -1 -1)
,,,mac "sub.remove_item" "" hDlg i
,,,out i
,,,0.4
,case IDOK
,case IDCANCEL
ret 1


#sub remove_item
function int'hDlg int'lb_item_index


SendMessage(id(3 hDlg) LB_DELETESTRING lb_item_index 0)
#2
The problem is because of the wait command in your dialog procedure
The dialog doesn't process messages while waiting.
You could use opt waitmsg 1 but better to move whole code to a sub function and run in a separate thread like so.
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 296 148 "Dialog" "4"
;3 ListBox 0x54230101 0x200 0 0 296 114 ""
;4 Button 0x54032000 0x0 5 119 48 14 "START"
;END DIALOG
;DIALOG EDITOR: "" 0x2040A00 "*" "" "" ""

str controls = "3"
str lb3=
;a
;b
;c
if(!ShowDialog(dd &sub.DlgProc &controls)) ret

#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 4
,int hlb=id(3 hDlg)
,mac "sub.remove_item" "" hlb
,case IDOK
,case IDCANCEL
ret 1

#sub remove_item
function cid
int amount i
amount=LB_GetCount(cid)
for(i amount-1 -1 -1)
,SendMessage(cid LB_DELETESTRING i 0)
,out i
,0.4
#3
Thanks!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)