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

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

By Zarko Gajic, About.com

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)

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

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

Easy ways to connect two computers for networking purposes. 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.