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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 910
  • Last Modified:

DBGrid multiselect

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
ralmada
Asked:
ralmada
1 Solution
 
EpsylonCommented:
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
 
skycrusherCommented:
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
 
ralmadaAuthor Commented:
Thank you Epsylon, you've been very helpful
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now