Hi,
I have used the OnDrawColumnCell event of the DBGridEh to solve the problem of the invisible cellbutton.
Below is my solution for this problem:
Code:
procedure TForm.DbGridEhDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh;
State: TGridDrawState);
{Put on the form a TImageList component with two bitmaps: [-] and [+].
Each bitmap has height = 9 and width = 9.
My TImageList component is named imgCellBtn.}
var
ImgIdx : Byte; // Inform the bitmap index of the imgCellBtn : TImageList
CellBtnRect,
ValueRect : TRect;
CellBtnState : Integer;
DBGrid : TDBGridEh;
begin
DBGrid := Sender as TDBGridEh;
with DBGrid do
begin
{The CellButton is on the Column with DataCol = 0.}
if (DataCol = 0) then
begin
CellBtnRect := Rect;
CellBtnRect.Left := Rect.Left + 1;
CellBtnRect.Top := Rect.Top + 3;
CellBtnRect.Height := 9;
CellBtnRect.Width := 9;
Canvas.FillRect(Rect);
CellBtnState := DFC_BUTTON or DFCS_BUTTONPUSH or DFCS_PUSHED or DFCS_FLAT;
DrawFrameControl(Canvas.Handle, CellBtnRect, DFC_BUTTON, CellBtnState);
if (gdFocused in State) then
begin
{pnlValues is the panel with the values of some fields that I want to show when the cellbutton is pressed.}
if (pnlValues.Visible) then
ImgIdx := 0 // [-]
else
ImgIdx := 1; // [+]
end
else
ImgIdx := 1; // [+]
{imgCellBtn is a TImageList with two 9x9 bitmaps: [-] and [+].}
imgCellBtn.Draw(Canvas, CellBtnRect.Left, CellBtnRect.Top, ImgIdx);
{The value of the Field of DataCol = 0 is drawn.}
ValueRect := Rect;
ValueRect.Left := CellBtnRect.Left + CellBtnRect.Width + 1;
ValueRect.Height := Rect.Height;
ValueRect.Width := Rect.Width - ValueRect.Left - 1;
DBGrid.DefaultDrawColumnCell(ValueRect, DataCol, Column, State);
end;
end;
end;