Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 29 Mar 2024, 15:07

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: 21 Feb 2019, 18:30 
Offline

Joined: 22 Mar 2016, 11:45
Posts: 26
Hello,
Is it possible to add a button or a checkbox to a specified column title?


Top
 Profile  
 
PostPosted: 27 Feb 2019, 14:35 
Offline

Joined: 08 May 2014, 18:06
Posts: 660
Hello

You can't add any control in the title cell but you can draw custom images and process mouse click
so it would looks like control is in the title cell.

Here is an example of code and demo.

Code:
procedure TForm1.DBGridEh1CellMouseClick(Grid: TCustomGridEh; Cell: TGridCoord;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer;
  var Processed: Boolean);
begin
  if (Cell.X = 1) and (Cell.Y = 0) and (Shift = []) then
  begin
    if (CheckBoxState = cbChecked) then
      CheckBoxState := cbUnchecked
    else
      CheckBoxState := cbChecked;
    DBGridEh1.InvalidateTitle;
  end;
end;

procedure TForm1.DBGridEh1DrawTitleCell(Grid: TCustomDBGridEh; ACanvas: TCanvas;
  const ARect: TRect; Params: TDBGridDrawTitleCellParamsEh;
  var Processed: Boolean);
var
  ForeInsideRect: TRect;
  CustomRect: TRect;
begin
  if Params.Column.FieldName = 'Name' then
  begin

    Grid.DrawTitleCellBackground(ACanvas, ARect, Params);
    ForeInsideRect := Params.ForeInsideRect;
    CustomRect := Params.ForeInsideRect;
    ForeInsideRect.Left := ForeInsideRect.Left + 20;
    CustomRect.Right := ForeInsideRect.Left;
    Params.ForeInsideRect := ForeInsideRect;
    Grid.DrawTitleCellForeground(ACanvas, ARect, Params);

    DrawCheckBoxEh(ACanvas.Handle, CustomRect, CheckBoxState, True, True, False, False);

    Processed := True;
  end;
end;


Attachments:
2019-02-27-CheckBoxInTitle.zip [5.21 KiB]
Downloaded 161 times
sshot-10.png
sshot-10.png [ 10.38 KiB | Viewed 1179 times ]

_________________
Best regards
EhLib Support Team
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group