Ver Mensaje Individual
  #5  
Antiguo 23-12-2018
feliz-58 feliz-58 is offline
Miembro
 
Registrado: sep 2012
Posts: 314
Reputación: 12
feliz-58 Va por buen camino
Cita:
Empezado por ecfisa Ver Mensaje
Hola.

Mediante un ejemplo, te agrego otra opción de borrado:
Código Delphi [-]
...

type
  TStringGrid = class(Grids.TStringGrid); // (*)

  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    btnDelete: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnDeleteRowClick(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation {$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  c,r,x: Integer;
begin
  x := 0;
  StringGrid1.Rows[0].CommaText := 'COL1,COL2,COL3,COL4,COL5';
  for r := StringGrid1.FixedRows to StringGrid1.RowCount-1 do
    for c := StringGrid1.FixedCols to StringGrid1.ColCount-1 do
    begin
      StringGrid1.Cells[c,r] := Format('cell %d', [x]);
      Inc(x);
    end;
  StringGrid1.Row:= StringGrid1.RowCount-1; // ir a la última fila
end;

procedure TForm1.btnDeleteRowClick(Sender: TObject);
begin
  if StringGrid1.Row > StringGrid1.FixedRows then
    StringGrid1.DeleteRow(StringGrid1.Row)
  else
    StringGrid1.Rows[1].Text := '';
end;
...
(*) Clase TStringGrid desprotegida para acceder al método protegido DeleteRow ( también podes acceder al método DeleteColumn )

Saludos
Con esto...
Código Delphi [-]
if SG.Row > SG.FixedRows then
   SG.DeleteRow(SG.Row)
  else
    SG.Rows[1].Text := '';

Cuando ya tienes varios articulos, y eliminas el primero, solo limpia la primera linea, es decir "No la elimina" alguna idea de como resolver esto?
Responder Con Cita