Problem with TCRDBGrid.DrawColumnCell

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
chuckbeasley

Problem with TCRDBGrid.DrawColumnCell

Post by chuckbeasley » Wed 21 Dec 2005 19:54

I'm trying to imbed a DateTimePicker in a CRDBGrid cell. However, when I click on the cell containing the date and the following code executes, nothing happens. Any clues?

procedure TForm1.CRDBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (Column.Field.DataType in [ftDateTime, ftTimeStamp]) then
with DateTimePicker do
begin
Left := Rect.Left + CRDBGrid1.Left + 1;
Top := Rect.Top + CRDBGrid1.Top + 1;
Width := Rect.Right - Rect.Right + 2;
Width := Rect.Right - Rect.Right + 2;
Height := Rect.Bottom - Rect.Top + 2;
Visible := True;
end;
end;
end;

chuckbeasley

Post by chuckbeasley » Wed 21 Dec 2005 20:45

Fixed it. Here's the source:

DateTimePicker.Visible := CRDBGrid1.SelectedField = DataModule1.adbndbDATE_TIME;
if DateTimePicker.Visible then
if gdFocused in State then
begin
DateTimePicker.Date := DataModule1.adbndbDATE_TIME.AsDateTime;
DateTimePicker.SetBounds(Rect.Left,Rect.Top, Rect.Right-Rect.Left,
Rect.Bottom-Rect.Top);
end;

Post Reply