delphi - How do I delete a TStringGrid row? -
i have tstringgrid, , want delete selected row. basic things i've tried delete last row. how delete arbitrary row?
if code you've tried deletes last row, you're decrementing rowcount
property. indeed makes modifications on end of list of rows. in mind, write code ensure row no longer want 1 @ end, , then delete last row. (the direct way move row, , there's moverow
method, it's protected. if wish call protected methods, though, may call deleterow
instead.)
using public , published members, it's possible write loop deletes arbitrary row. example, here's code inspired scalabium software's faq on topic:
procedure deleterow(grid: tstringgrid; arow: integer); var i: integer; begin := arow grid.rowcount - 2 grid.rows[i].assign(grid.rows[i + 1]); grid.rowcount := grid.rowcount - 1; end;
it copies contents of each row below 1 wish delete row above. @ end of loop, row wish delete has been overwritten (by row below it) , there 2 copies of final row. deletes final row.
to delete current row of grid, call function this:
deleterow(grid, grid.row);
Comments
Post a Comment