Solved

making multiselections in dbgrid the windows way?

Posted on 2000-03-13
18
372 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
ID: 2613409
listening . . .
0
 
LVL 12

Expert Comment

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

Cheers,

Raymond.
0
 
LVL 17

Expert Comment

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

Expert Comment

by:Asw
ID: 2613677
listening.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2614858
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
ID: 2614956
listening...
0
 
LVL 4

Expert Comment

by:jeurk
ID: 2615242
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
ID: 2615315
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
ID: 2615412
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 2615453
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
ID: 2615513
www.tmssoftware.com has some nice components too.
0
 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 2616021
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
ID: 2616148
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
ID: 2616672
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
ID: 2617581
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
ID: 2625663
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
ID: 2625678
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
ID: 2626916
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

11 Experts available now in Live!

Get 1:1 Help Now