Solved

Select DBGrid rows by Double  Click

Posted on 2013-12-23
6
1,698 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 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 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
Technology Partners: 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 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 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month3 days, 23 hours left to enroll

630 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