Solved

DBGrid multiselect

Posted on 2000-02-28
3
888 Views
Last Modified: 2008-03-10
How can I handle a multiselection in a DBGrid component.
I mean, I've selected several rows, but I don't know how to identify them.
The only thing I could do is to know how many items did I select, with the DBGrid.SelectedRows.Count property
0
Comment
Question by:ralmada
3 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 50 total points
ID: 2567057
It goes like this:

procedure TForm1.Button1Click(Sender: TObject);
var
  i, j: Integer;
  s: string;
begin
  if DBGrid1.SelectedRows.Count>0 then
    with DBGrid1.DataSource.DataSet do
      for i:=0 to DBGrid1.SelectedRows.Count-1 do
      begin
        GotoBookmark(pointer(DBGrid1.SelectedRows.Items[i]));
        for j := 0 to FieldCount-1 do
        begin

          if (j>0) then s:=s+', ';
          s:=s+Fields[j].AsString;
        end;
        Listbox1.Items.Add(s);
        s:= '';
      end;
end;
0
 

Expert Comment

by:skycrusher
ID: 2567077
You can use SelectedRows to handle them.
just type (in Delphi 3 or above)

dbgrid1.selectedrows. then wait for a
second. You should see the code
completion displaying several methods
for selectedrows.

there are several method available to
handle your problem, because
SelectedRows is a set of bookmarks to
all the records in the dataset that
correspond to rows selected in the grid

some of the methods are :
find, indexof, currentrowselected,
items.

I hope this answer can solve your
problem

regards,
skycrusher
0
 
LVL 41

Author Comment

by:ralmada
ID: 2569907
Thank you Epsylon, you've been very helpful
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

13 Experts available now in Live!

Get 1:1 Help Now