Recent

Author Topic: how delete line in StringGrid  (Read 16133 times)

Robson

  • New Member
  • *
  • Posts: 47
how delete line in StringGrid
« on: January 12, 2011, 08:24:33 pm »
var
  cl, ln, ln_atual: integer;
begin
  if sgCampos.Row < 0 then
  begin
    ShowMessage('Selection Line.');
    Exit;
  end;

  for ln:= sgCampos.Row to sgCampos.RowCount - 1 do
     for cl:= 0 to sgCampos.ColCount -1 do
        sgCampos.Cells[cl, ln]:= sgCampos.Cells[cl, ln+1];

  sgCampos.RowCount := sgCampos.RowCount -1;
end;

MsgDialog Error:

Index Out of range Cell[Col=0 Row=5].

Press OK to ignore and risk data corruption.
Press Cancel to kill the program.

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: how delete line in StringGrid
« Reply #1 on: January 12, 2011, 08:41:07 pm »
for one of my software (not released yet) i made this function:

//Delete a row of a TStringGrid
procedure DeleteRow(StringGrid: TStringGrid; ARow: integer);
var
  i, j: integer;
begin
  with StringGrid do
  begin
    for i := ARow to RowCount - 2 do
      for j := 0 to ColCount - 1 do
        Cells[j, i] := Cells[j, i + 1];
    RowCount := RowCount - 1;
  end;
end;

You can use call easily:

DeleteRow(sgCampos, sgCampos.Row);

Regards,
Fabien Wang
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

Robson

  • New Member
  • *
  • Posts: 47
Re: how delete line in StringGrid
« Reply #2 on: January 12, 2011, 08:55:08 pm »
how not to delete the first one is the header.

thanks

Robson

  • New Member
  • *
  • Posts: 47
Re: how delete line in StringGrid
« Reply #3 on: January 12, 2011, 09:01:26 pm »
ok:

if StringGrid.RowCount = 1 then
    exit; 

 

TinyPortal © 2005-2018