Solved

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

Posted on 2004-09-12
3
700 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

11 Experts available now in Live!

Get 1:1 Help Now