Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multirow Delete in Grid
#1
I seem to have come across a puzzler!
If I want to delete (multi-)selected rows from a grid, I first find out the selected rows using RowsSelectedGet and then loop then run through the array with a for-counter-loop of RowDelete delete statements for each element in the array that RowsSelectedGet filled.
BUT each time I delete a row, the row count changes!
Is there a way to delete all rows at once or do I have to put in an accounting factor for the row deletion into each turn of the for-counter-loop e.g. subtract the counter integer from the row number?
S
#2
puzzle solved!
The loop counter subtraction works!


Code:
Copy      Help
ARRAY(int) arrintSelectedRowsForDelete
int TotalSelectedRowsForDelete = g0.RowsSelectedGet(arrintSelectedRowsForDelete)
for _i 0 TotalSelectedRowsForDelete
,g0.RowDelete(arrintSelectedRowsForDelete[_i]-_i);;need the counter correction since the row numbers change as the delete occurs each time
,

Is there a problem instance where this solution might cause an error?
S
#3
When deleting multiple items from an array, grid etc, it's better to start from the end.

Function Dialog_grid_delete
Code:
Copy      Help
,case 4 ;;Delete
,ARRAY(int) a
,g.RowsSelectedGet(a)
,for i a.len-1 -1 -1
,,g.RowDelete(a[i])


Forum Jump:


Users browsing this thread: 1 Guest(s)