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

x
?
Solved

Select DBGrid rows by Double  Click

Posted on 2013-12-23
6
Medium Priority
?
1,832 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 38

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 28

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 28

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 38

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 38

Accepted Solution

by:
Geert Gruwez earned 1000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

972 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