unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids;
type
TMyDBGrid =
class(TDBGrid)
private
FOnTitleRightClick: TDBGridClickEvent;
protected
procedure TitleRightClick(Column: TColumn);
dynamic;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
override;
property OnTitleRightClick: TDBGridClickEvent
read FOnTitleRightClick
write FOnTitleRightClick;
end;
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
MyDBGrid1: TMyDBGrid;
procedure MyTitleClick(Column: TColumn);
procedure MyTitleRightClick(Column: TColumn);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TMyDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var
Cell: TGridCoord;
begin
inherited MouseUp(Button, Shift, X, Y);
Cell := MouseCoord(X,Y);
if (Button = mbright)
and (Cell.X >= IndicatorOffset)
and (Cell.Y = 0)
then
TitleRightClick(Columns[RawToDataColumn(Cell.X)]);
end;
procedure TMyDBGrid.TitleRightClick(Column: TColumn);
begin
if Assigned(FOnTitleRightClick)
then FOnTitleRightClick(Column);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyDBGrid1 := TMyDBGrid.Create(Self);
MyDBGrid1.Parent := Self;
with MyDBGrid1.Columns.Add
do
Title.Caption := '
Test1';
with MyDBGrid1.Columns.Add
do
Title.Caption := '
Test2';
MyDBGrid1.OnTitleClick := MyTitleClick;
MyDBGrid1.OnTitleRightClick := MyTitleRightClick;
end;
procedure TForm1.MyTitleClick(Column: TColumn);
begin
ShowMessage('
Links - ' + Column.Title.Caption);
end;
procedure TForm1.MyTitleRightClick(Column: TColumn);
begin
ShowMessage('
Rechts - ' + Column.Title.Caption);
end;
end.