Solved

making multiselections in dbgrid the windows way?

Posted on 2000-03-13
18
365 Views
Last Modified: 2010-04-04
Hi, does anyone know how I should alter the dbgrid so I can make multiple selections like in the standard windows? i.e. selecting the first, holding down shift and make the last selection and all in between gets selected.
Thanks, Pascal
0
Comment
Question by:corpa
  • 5
  • 4
  • 3
  • +6
18 Comments
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
listening . . .
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
You can already do this usig CTRL (not standard I know - but it's there...)

Cheers,

Raymond.
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
meikl,
i thought you had example of multiple selections using shift.
0
 
LVL 1

Expert Comment

by:Asw
Comment Utility
listening.
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
to barry,
so that you can assimilate it ;-))
no, have no sample yet, which will work properly, but i'm working on it.

meikl
0
 
LVL 9

Expert Comment

by:ITugay
Comment Utility
listening...
0
 
LVL 4

Expert Comment

by:jeurk
Comment Utility
how to do it with ctrl is here :
http://www.torry.webnorth.com/samples/samples/rsdtip01.zip

I'm giving the link because of the licence of the sample asking me to.

I know you are talking about a selection using shift. But it's just in case...

CU.
0
 
LVL 2

Expert Comment

by:Tussin
Comment Utility
just add dgMultiSelect to TDBGrid.Options

you also can use this command

dbgrid1.Options:=dbgrid1.Options+[dgMultiSelect];

Now, you can hold down shift button and press down as you want.

Note. I use delphi 5
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
hmm tussin,

this will not work, if you click one record and press shift and click another record, as you do in the explorer with files.

just to remark

meikl
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
hi again,

there is a comercial grid, which does it and much more. take a look to:

http://www.devexpress.com/products/vcl/product.asp?prodid=10

meikl
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
www.tmssoftware.com has some nice components too.
0
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
Comment Utility
Tussin ,
you should read the questions and comments better before posting answers..


Corpa ,
is this what your after:
//multiselect set to true in object inspector

var
  Form1: TForm1;
  firstpoint, thispoint: tpoint;
  thisfield : string;
 

implementation

uses Unit2,Unit3;

{$R *.DFM}

procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
if (dgmultiselect in dbgrid1.options) then
  if getkeystate(vk_shift) < short(0) then begin
   getcursorpos(thispoint);
    while not table1.eof and not table1.bof and
     not (dbgrid1.datasource.dataset.fields[0].asstring = thisfield) do     begin
     if thispoint.y > firstpoint.y then table1.prior
     else table1.next;
   dbgrid1.selectedrows.currentrowselected := true;
  end;
 end;
getcursorpos(firstpoint);
 thisfield := dbgrid1.datasource.dataset.fields[0].asstring;
end;


Regards Barry
0
 
LVL 27

Expert Comment

by:kretzschmar
Comment Utility
hi barry,

just to comment, not evaluated yet,
what, if the scrollbar is used, to scroll the record into view, which will end the selection-range and the thispoint.y is lower as firstpoint.y, but i've scrolled forward?

meikl
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
mmm.. how annoying ,clicking on a scrollbar selects a record.

ok i dont like scrollbars anymore it makes this routine look a bit silly.
it still selects the records as it should but also the top or bottom record in view is selected depending on which way is scrolled.
when you try it you will see what i mean.
i suppose we could do
ShowScrollbar( dbgrid1.handle, SB_VERT, False );
and create our own scrollbar that didnt select records when clicked ..
maybe we should try making component for all this..

0
 

Author Comment

by:corpa
Comment Utility
Tussin,
I'm sorry but your answer really isn't acceptable, but as you can see in the comments I guess you found that out allready by yourself.

Meikl,
That commercial component is just perfect, it really does the trick, but also too expencive :(

Barry,
interesting stuff, i'll play around with it a little.

In the meantime keep coming up with new idea's. I think there are more people interested in this feature as I look to the comments.

thank you very much so far,
Pascal
0
 

Author Comment

by:corpa
Comment Utility
Hello Barry,

I just played around with your sugestion and look, I found the solution.
But one should work with the DBGridPlus component that I found on the Delphi superpage somewhere.
Try http://ftp/d20free/dbgrdpls.zip
It has this OnChangeDrawing event where you can do nice things.
No more annoying scrollbar side effects.

Ok, here's what I made of your code:

----------------------------------------------------------
var
  Form1: TForm1;
  firstpoint, thispoint: tpoint;
  thisrec,selcount : integer;

implementation

{$R *.DFM}

procedure TForm1.FormShow(Sender: TObject);
begin
 //setting initial value
 selcount := 0;
end;

procedure TForm1.DBGridPlus1CellClick(Column: TColumn);
begin
 if (dgmultiselect in dbgridPlus1.options) then
  if (getkeystate(vk_shift) < short(0)) and (selcount > 0) then
   begin
    getcursorpos(thispoint);
    table1.DisableControls;
    while not table1.eof and not table1.bof and
          not (table1.RecNo = thisrec) do
       begin
         if thispoint.y > firstpoint.y then table1.prior
         else table1.next;
         dbgridPlus1.selectedrows.currentrowselected := true;
       end;
    table1.EnableControls;
   end
   else
   begin
    getcursorpos(firstpoint);
    thisrec := table1.RecNo;
   end;
 selcount := dbgridPlus1.selectedrows.Count;
end;

procedure TForm1.DBGridPlus1ChangeDrawing(Sender: TObject; DataCol,
  DataRow: Integer; AState: TGridDrawState; var Highlighted: Boolean);
begin
  Highlighted := (sender as TDBGridPlus).selectedrows.currentrowselected;
end;
----------------------------------------------------------

I will give you half the credit since you leaded me on track, ok.

Regards, Pascal
0
 

Author Comment

by:corpa
Comment Utility
Wel if the link to DBGridPlus doesn't work, let me know and I can mail it to ya.

Pascal
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
hi,
looKs good would you mind i try that component ,the ftp seems always busy so hope you can send.

Inthe@Future-Software-House.co.uk

cheers
  Barry

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

763 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

8 Experts available now in Live!

Get 1:1 Help Now