Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-09-12
3
714 Views
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:

MyDBGrid.SelectedRows.CurrentRowSelected:=True;

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

Any Idea?
0
Comment
Question by:setankabir
  • 2
3 Comments
 
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;
begin
  //example to select first, a looked up records and the last
  //record programmatically

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

  dbgrid1.DataSource.DataSet.GotoBookmark(bkm);
  dbgrid1.DataSource.DataSet.EnableControls;
end;

Regards
Pierre
0
 

Author Comment

by:setankabir
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.
0
 
LVL 14

Accepted Solution

by:
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…

809 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