Solved

dgIndicator click event of dbGrid, Delphi7

Posted on 2008-06-20
4
1,165 Views
Last Modified: 2012-06-21
Hello Experts,
I have a question regarding DBGrid.
How do i capture the event of dgIndicator click.
OnCellClick event exists but is there any method to find out the event of dgIndicator click.

Thanks
0
Comment
Question by:Asmitagoyal
  • 2
  • 2
4 Comments
 
LVL 36

Accepted Solution

by:
Geert Gruwez earned 75 total points
ID: 21829989
looks like you'll have to alter the MouseUp procedure in a DBGrid descendent

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DB, DBAccess, Ora, MemDS;

type
  TIndicatorClickEvent = procedure (Sender: TObject; ARow: Integer) of object;

  TMyDBGrid = class(TDBGrid)
  private
    FOnIndicatorClick: TIndicatorClickEvent;
  protected
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure IndicatorClick(ARow: Integer); dynamic;
  published
    property OnIndicatorClick: TIndicatorClickEvent read FOnIndicatorClick write FOnIndicatorClick;
  end;

  TForm1 = class(TForm)
    DBGrid: TDBGrid;
    ds: TDataSource;
    OraQuery: TOraQuery;
    OraSession: TOraSession;
    procedure FormCreate(Sender: TObject);
  private
    procedure dgIndicator(Sender: TObject; ARow: Integer);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyDBGrid }

procedure TMyDBGrid.IndicatorClick(ARow: Integer);
begin
  if Assigned(FOnIndicatorClick) then
    FOnIndicatorClick(Self, ARow);
end;

procedure TMyDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
  SaveState: TGridState;
  FirstCell: TRect;
begin
  SaveState := FGridState;
  inherited MouseUp(Button, Shift, X, Y);
  if (SaveState = gsRowSizing) or (SaveState = gsColSizing) or
    ((InplaceEditor <> nil) and (InplaceEditor.Visible) and
     (PtInRect(InplaceEditor.BoundsRect, Point(X,Y)))) then Exit;
  FirstCell := CellRect(1, 1);
  Cell := MouseCoord(X,Y);
  if (Button = mbLeft) and (X <= IndicatorWidth) and (Y >= FirstCell.Top) then
    IndicatorClick(Cell.Y);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  with TMyDBGrid.Create(Self) do
  begin
    Parent := Self;
    OnIndicatorClick := dgIndicator;
    DataSource := ds;
  end;
end;

procedure TForm1.dgIndicator(Sender: TObject; ARow: Integer);
begin
  ShowMessage('Row indicator: ' + IntToStr(ARow));
end;

end.
0
 
LVL 10

Expert Comment

by:dinilud
ID: 21830884
For discussion

procedure TMyDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Cell: TGridCoord;
  SaveState: TGridState;
  //FirstCell: TRect;
begin
  SaveState := FGridState;
  inherited MouseUp(Button, Shift, X, Y);
  if (SaveState = gsRowSizing) or (SaveState = gsColSizing) or
    ((InplaceEditor <> nil) and (InplaceEditor.Visible) and
     (PtInRect(InplaceEditor.BoundsRect, Point(X,Y)))) then Exit;
  //FirstCell := CellRect(1, 1);
  Cell := MouseCoord(X,Y);
  if (Button = mbLeft) and (dgIndicator in Options) and (X <= IndicatorWidth) then
  begin
     if (dgTitles in Options) and (Cell.Y > 0) then exit;
     IndicatorClick(Cell.Y);
  end;
end;



................
................


  with TMyDBGrid.Create(Self) do
  begin
    Parent := Self;
    Options:=Options-[dgTitles];
    OnIndicatorClick := dgIndicator;
    DataSource := DataSource1 ;
  end;
0
 
LVL 36

Expert Comment

by:Geert Gruwez
ID: 21830916
a B for this solution ?
And what didn't work ?
0
 
LVL 10

Expert Comment

by:dinilud
ID: 21831002
While i am studing your answer i found
   if title not exist,it gives wrong answer. thats all.
this is not for irritating you.


with TMyDBGrid.Create(Self) do
  begin
    Parent := Self;
    Options:=Options-[dgTitles];
    OnIndicatorClick := dgIndicator;
    DataSource := DataSource1 ;
  end;
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

20 Experts available now in Live!

Get 1:1 Help Now