Solved

Select DBGrid rows by Double  Click

Posted on 2013-12-23
6
1,585 Views
Last Modified: 2014-04-25
Good day:
I am using Delphi 2010, I would like to select multiple rows by double click each row ( instead of Ctrl+Click) ,
0
Comment
Question by:khaled salem
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39739389
i'd like the coffee machine to start by clicking on CTRL-SHIFT-ALT+C+O+F+F+E+E
alas, the blasted coffee machine won't listen.
there is lot of things people would like changed, but what is the point ?

double click means opening more info on the row in a separate window

with ctrl-click it requires 11 clicks to multiselect 10 separate rows
you can even use sticky keys (Keep Shift down for 8 seconds to find that feature) to keep the control key down, so you don't have to keep pressing it

what is the point in changing the behavior of the double click ?
0
 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39740050
This is not usual, and not elegant solution too but can be done:

1. copy DBGrids.pas from Delphi's source folder into projects folder
2. open it in delphi
3. search for TCustomDBGrid.MouseDown procedure - this one you should modified
4. find this code:
if (ssDouble in Shift) and (Button = mbLeft) then
  begin
    DblClick;
    Exit;
  end;

Open in new window


... and replace this with:
if (ssDouble in Shift) and (Button = mbLeft) then
  begin
    if FDatalink.Active then
      with Cell do
      begin
        BeginUpdate;   { eliminates highlight flicker when selection moves }
        try
          FDatalink.UpdateData; // validate before moving
          HideEditor;
          if (Button = mbLeft) and (dgMultiSelect in Options) and FDatalink.Active then
            with FBookmarks do
            begin
              FSelecting := False;
              CurrentRowSelected := not CurrentRowSelected
            end;
        finally
          EndUpdate;
        end;
      end;

    DblClick;
    Exit;
  end;

Open in new window


...and little lower find:
...
            FSelecting := False;
            if ssCtrl in Shift then
              CurrentRowSelected := not CurrentRowSelected
            else
            begin
              Clear;
              CurrentRowSelected := True;
            end;

Open in new window


... replace it with:
            FSelecting := False;
            if ssCtrl in Shift then
            begin
              Clear;
              CurrentRowSelected := True;
            end;

Open in new window


so, this will reset selection again to only row using ctrl key + mouse down.
In project source (FormCreate event) or in design define multiselect:
DBGrid1.Options := DBGrid1.Options + [dgMultiSelect, dgRowSelect];

Open in new window


Compile it...
0
 

Author Comment

by:khaled salem
ID: 39743882
nothing happened, i can not select multiple rows by double clicking .
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 26

Expert Comment

by:Sinisa Vuk
ID: 39745157
This is my example. I use Ado, so just do connect to your database. Add modified DBGrid.pas to my project. It works for me. I use D2007 but should work on all versions.
multisel.zip
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 39750982
are you using the standard TDbGrid component or an other component ?

with another component there is probably no point in altering the behavior as with newer versions you will lose the functionality you added
besides, it's nearly impossible if you don't have the source

i'm not sure about your users, but the users i work with had some advanced features they wanted in the grids, so we decided to buy devexpress quantumgrid
no point in trying to change the behaviour in that grid
0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 500 total points
ID: 39750993
the baviour with sticky keys is easier in windows to do:
it even works in excel, word, any other app

open your app with the grid with live data

hit shift 5 times fast after each other
> a prompt will appear to activate sticky keys
hit yes

hit ctrl 2 times fast after each other

click record 2 > it will be selected for multi select now
click record 4 > it will be selected for multi select now
click record 7 > it will be selected for multi select now

hit ctrl to deactivate the ctrl-lock

if you click a record now, it will be the only 1 selected

there is no code at all required to do this
works with any grid (delphi, excel, etc ... )
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 60
Delphi inherited method 6 70
Convert MS Word document to a PDF file 9 82
I want to use librsync in my Delphi backup application. 3 50
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…
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…
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…

803 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