Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-07

TStringGrid, One click, multiple events.

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dave Coventry

Hi,

I'm sure this has been covered often, but none of my searches seems to find it.

I have a routine to remove a row from a TStringGrid if the user selects it.

The problem is that the onSelection event seems to be trigered twice:

procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: Integer);
var i:integer;
begin
  if messageDlg('Remove
'+StringGrid1.Cells[aCol,aRow]+'?',mtInformation,[mbYes,mbNo],0)=mrYes
then
  begin
    for i:=arow to StringGrid1.RowCount-2 do
    begin
      StringGrid1.Cells[0,i]:=StringGrid1.Cells[0,i+1];
      StringGrid1.Cells[1,i]:=StringGrid1.Cells[1,i+1];
    end;
    StringGrid1.RowCount:=StringGrid1.RowCount-1;
  end;
end;

The user will click the item to be removed, the dialog will appear asking for confirmation to delete the row, but on clicking yes, while the row is deleted as expected, the dialog pops up again, asking the user if the next line should be deleted.

Reply by email

Coppola Ing. Salvatore
to Dave Coventry
Dave Coventry wrote 35 lines
Hi, I'm sure this has been covered often, but none of my searches seems to find it. I have a routine to remove a row from a TStringGrid if the user selects it. The problem is that the onSelection event seems to be trigered twice: procedure TForm1.StringGrid1Selection(Sender: TObject; aCol, aRow: Integer); var i:integer; begin if messageDlg('Remove '+StringGrid1.Cells[aCol,aRow]+'?',mtInformation,[mbYes,mbNo],0)=mrYes then begin for i:=arow to StringGrid1.RowCount-2 do begin StringGrid1.Cells[0,i]:=StringGrid1.Cells[0,i+1]; StringGrid1.Cells[1,i]:=StringGrid1.Cells[1,i+1]; end; StringGrid1.RowCount:=StringGrid1.RowCount-1; end; end; The user will click the item to be removed, the dialog will appear asking for confirmation to delete the row, but on clicking yes, while the row is deleted as expected, the dialog pops up again, asking the user if the next line should be deleted. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

Out of your question
you can use
TStringGrid.DeleteColRow instead of your code
Salvatore

Reply by email