1. Home
  2. Computing & Technology
  3. Delphi Programming

How to select all rows (records) in a DBGrid from code

By , About.com Guide

When the DBGrid's Options property includes dgRowSelect and dgMultiSelect, users can select multiple rows in a grid.
Here's how to select the entire DBGrid from code:

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure DBGridSelectAll(AGrid: TDBGrid) ;
begin
   AGrid.SelectedRows.Clear;
   with AGrid.DataSource.DataSet do
   begin
     DisableControls;
     First;
     try
       while not EOF do
       begin
         AGrid.SelectedRows.CurrentRowSelected := True;
         Next;
       end;
     finally
       EnableControls;
     end;
   end;
end;

//Usage:
//DBGridSelectAll(DBGrid1) ;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Delphi 8 IDE tricks - Error Insight
« How to open a password protected Paradox DB (if you do not know the password)

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2004 Delphi Tips
  7. How to select all rows (records) in a DBGrid from code

©2009 About.com, a part of The New York Times Company.

All rights reserved.