PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → List box question
List box question
Débuté par Sammy Broeders, 21 aoû. 2018 13:12 - 7 réponses
Posté le 21 août 2018 - 13:12
Hello all,

I have a list box filled with a data file, now i want to select one or more items in this list box and delete it from this list box/datafile to another list box/datafile. I use the code below but it is not working ok, most of the time other rows who are not selected converted to the other listbox.

FOR EACH SELECTED ROW OF LIST_all
HReadSeek(VoertuigSoort,Nummer,LIST_all)
VoertuigSoortGroep1 = VoertuigSoort
HAdd(VoertuigSoortGroep1)
HDelete(VoertuigSoort)
END

ListDisplay(LIST_all)
ListDisplay(LIST_filter1)
Posté le 21 août 2018 - 20:46
Hi Sammy,

If you delete stuff in a for each loop, you always have to do it in reverse order FOR Each xxx FromEnd, otherwise the delete will interfere with the browse.
And do a listdisplay(xxx, taInit) afterwards.

Kind regards,
Piet
Posté le 22 août 2018 - 18:46
Thanks Piet,

But where can i place ''fromend'' ?

Sammy
Posté le 22 août 2018 - 20:26
Sammy

something like this:
//Get the count of selected rows nCount is int = TableSelectCount(TABLE_Orders) nRow is int //Make sure you have at least 1 row IF nCount > 0 THEN //Now we step form back to front of the table FOR i = nCount TO 1 STEP -1 //Select the last row first and move 1 by 1 to the first nRow = TableSelect(TABLE_Orders,i) //Do your magic here END END END ELSE Info("You must select at least one row to preform this operation! ") END
DW
Posté le 22 août 2018 - 22:03
Hi Sammy,

I see now that there is no FromEnd for "FOR EACH Selected".
A very simple solution would be to gather the IDs first:
ar_Selection is array of int FOR EACH SELECTED ROW OF LIST_all ArrayAdd(ar_Selection,LIST_all) END FOR EACH ID OF ar_Selection HReadSeek(VoertuigSoort,Nummer,ID) VoertuigSoortGroep1 = VoertuigSoort HAdd(VoertuigSoortGroep1) HDelete(VoertuigSoort) END ListDisplay(LIST_all) ListDisplay(LIST_filter1) Kind regards,
Piet
Posté le 23 août 2018 - 11:41
Piet,

Your first solution works ok, the second post gives the same problem as i had.

Thanks
Posté le 23 août 2018 - 14:49
Hi Sammy,

You probably mean DW's solution or did the FromEnd work?
Just wondering: is the list a simple list or is it a list with a returned value?
IOW, does it return the list index or the linked value?

Kind regards,
Piet
Posté le 24 août 2018 - 16:50
Sorry your right, i mean DW`s solution.