Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
4
Erster Beitrag:
vor 4 Jahren, 7 Monaten
Letzter Beitrag:
vor 4 Jahren, 7 Monaten
Beteiligte Autoren:
Giu, Arie, DW

Iterating a Table control to delete rows

Startbeitrag von Giu am 30.05.2013 10:17

Hi all,

I'm having troubles trying to iterate a TABLE control (filled by programming), and deleting some "checked" rows.
[attachment 382 Screenshot-30_05_201312_08_35.jpg]

As you can see, I want to iterate this TABLE to delete the records checked. The process, should delete associated records from the database too.

I have this code:

FOR EACH ROW OF TABLE_Ticket
IF TABLE_Ticket.COL_DEL THEN
IF HReadSeekFirst(MesasAbiertasDetalle,ProductosID, TABLE_Ticket.COL_ProdID)
HDelete(MesasAbiertasDetalle,hCurrentRecNum)
TableDelete(TABLE_Ticket)
END
END
END


If record has COL checked, then search for this record in database to delete it, and delete the row from the table.

WIth 1 record works like a charm, but when more than 1 record is checked, don't delete all.

From the precious capture, If I press to to the process, after finish I get this capture TABLE.
[attachment 383 Screenshot-30_05_201312_12_23.jpg]

1 Record wasn't deleted. If I run again the process, then, this checked record is deleted.

Trying again. If I check the 2 firsts rows, only first is deleted. I guess is something related to changin the value of TableCount and repositioning rows. Example: In this example, first record is deleted, and all rows moves -1, then iration goes for second record, but second record, now is first, and is not deleted.

Some idea how to achieve this? I know it's very simple, but I'm away from programming some years, and don't know exactly how to do it correctly.

Regards.

Antworten:

Hello Giu,

1) Use a for loop and start from the end to 1

The reason if you are looping thru a table and delete 3, 4 becomes 3 and so on. Now it will skip once 4 thinking it is 3.


nCount is int = tablecount(TABLE_Ticket)
FOR i = nCount TO 1 STEP -1
//I change the brackets to curly brackets to show up "{" = "["
IF COL_DEL{i} THEN
IF HReadSeekFirst(MesasAbiertasDetalle,ProductosID, COL_ProdID{i})
HDelete(MesasAbiertasDetalle,hCurrentRecNum)
TableDelete(TABLE_Ticket)
END
END
END


DW

von DW - am 30.05.2013 10:59
Quote
DW
Hello Giu,

1) Use a for loop and start from the end to 1

The reason if you are looping thru a table and delete 3, 4 becomes 3 and so on. Now it will skip once 4 thinking it is 3.


nCount is int = tablecount(TABLE_Ticket)
FOR i = nCount TO 1 STEP -1
//I change the brackets to curly brackets to show up "{" = "["
IF COL_DEL{i} THEN
IF HReadSeekFirst(MesasAbiertasDetalle,ProductosID, COL_ProdID{i})
HDelete(MesasAbiertasDetalle,hCurrentRecNum)
TableDelete(TABLE_Ticket)
END
END
END


DW


Works great. Thanks a lot.

von Giu - am 30.05.2013 15:05
WD18 new feature 68: TableDeleteSelect(), to delete all selected rows of a table-control at once :spos:

von Arie - am 30.05.2013 18:57
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.