Solved

DBGrid multiselect

Posted on 2000-02-28
3
899 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

821 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