Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-09-12
3
Medium Priority
?
738 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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

963 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