?
Solved

DBGrid multiselect

Posted on 2000-02-28
3
Medium Priority
?
904 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 200 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

719 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