Solved

Select DBGrid rows by Double  Click

Posted on 2013-12-23
6
1,523 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:khaledsalem
  • 3
  • 2
6 Comments
 
LVL 36

Expert Comment

by:Geert Gruwez
Comment Utility
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 25

Expert Comment

by:Sinisa Vuk
Comment Utility
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:khaledsalem
Comment Utility
nothing happened, i can not select multiple rows by double clicking .
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 25

Expert Comment

by:Sinisa Vuk
Comment Utility
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 36

Expert Comment

by:Geert Gruwez
Comment Utility
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 36

Accepted Solution

by:
Geert Gruwez earned 500 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

17 Experts available now in Live!

Get 1:1 Help Now