How to select current row or particular rows programmatically in multiselect mode?

Posted on 2004-09-12
Last Modified: 2010-04-05
In multiselect mode, normally we hold ctrl key and click the fixed-row (in the most left part of DBGrid) to select rows.

How to select current row or particular rows programmatically in multiselect mode?

By the way, I've tried this code:


But the problem is, the fixed-row is not highlighted.

Any Idea?
Question by:setankabir
  • 2
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 12042230
I just dropped a grid, datasource and TTable on a form and used the DBDemos vendors.db table to illustrate:

procedure TForm1.Button1Click(Sender: TObject);
var bkm: pointer;
  //example to select first, a looked up records and the last
  //record programmatically

  bkm:= dbgrid1.DataSource.DataSet.GetBookmark;
  dbgrid1.SelectedRows.CurrentRowSelected:= true;
  if dbgrid1.DataSource.DataSet.Locate('VendorNo', 3819, [loCaseInsensitive])
  then dbgrid1.SelectedRows.CurrentRowSelected:= true;
  dbgrid1.SelectedRows.CurrentRowSelected:= true;



Author Comment

ID: 12053354
I think that approach also won't highlight the fixed-row (in the most left part of DBGrid) as when we manually hold ctrl key and click the fixed-row to select rows.
LVL 14

Accepted Solution

Pierre Cornelius earned 50 total points
ID: 12053733
I tested it on my machine and get exact same results as when doing so manually as when doing so programmatically.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 210
proper way to parse text with delphi 7 100
Virtuailstring tree compare node issue 14 105
Multiple image collision 13 69
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With  eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now