Search code examples
delphi-7dbgrid

As in Delphi at ctrl + a to allocate all line in dbgrid


did when pressing button select all the lines in dbgrid, can I select all the lines when ctrl + a is pressed?

function GridSelectAll(Grid: TDBGrid): Longint;
begin
  Result := 0;
  Grid.SelectedRows.Clear;
  with Grid.Datasource.DataSet do
  begin
    First;
    DisableControls;
    try
      while not EOF do
      begin
        Grid.SelectedRows.CurrentRowSelected := True;
        inc(Result);
        Next;
      end;
    finally
      EnableControls;
    end;
  end;
end;

procedure TForm2.btn13Click(Sender: TObject);
begin
  GridSelectAll(dbgrd1);
end;

Solution

  • procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin   if (ssCtrl in Shift) and (Key = $41) then
        then  GridSelectAll(dbgrd1); end;