Recent

Author Topic: OnMouseDown for each column title at DBGrid  (Read 1921 times)

dsyrios

  • Jr. Member
  • **
  • Posts: 57
OnMouseDown for each column title at DBGrid
« on: June 26, 2015, 09:06:41 am »
Please,
I want to handle the Left or Right-click of the mouse
on the Header/Titles of a DBGrid for each column.
I've done a try with OnMouseDown, (see the attachment)
but I wonder if there is something else more efficient and net.
Thanks in advance.
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1

balazsszekely

  • Guest
Re: OnMouseDown for each column title at DBGrid
« Reply #1 on: June 26, 2015, 10:18:32 am »
Code: [Select]
procedure TForm1.DBGrid1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  ACol, ARow: Integer;
begin
  if Y < DBGrid1.DefaultRowHeight then
  begin
    (Sender as TDBGrid).MouseToCell(X, Y, ACol, ARow);
    case Button of
       mbRight: ShowMessage('Right mouse down on column title: ' + IntToStr(ACol));
       mbLeft:  ShowMessage('Left mouse down on column title: ' + IntToStr(ACol));
    end;
  end; 
end;
« Last Edit: June 26, 2015, 10:48:21 am by GetMem »

dsyrios

  • Jr. Member
  • **
  • Posts: 57
Re: OnMouseDown for each column title at DBGrid
« Reply #2 on: June 26, 2015, 02:13:02 pm »
Thanks @GetMem,
it's much better, it's the right way !
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1

 

TinyPortal © 2005-2018