Solved

Select DBGrid rows by Double  Click

Posted on 2013-12-23
6
1,671 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
[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
  • 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 27

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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