在窗口放一个dbgrid,dbdatetimepicker,将dbdatetimepicker设置visible:=false;
procedure TForm1.DBGrid1SelectEditor(Sender: TObject; Column: TColumn;
var Editor: TWinControl);
begin
if (DBGrid1.SelectedField.DataType=ftDateTime) or
(DBGrid1.SelectedField.DataType=ftDate)
then begin
DBDateTimePicker1.DataSource:=DBGrid1.DataSource;
DBDateTimePicker1.DataField:=DBGrid1.SelectedField.fieldname;
DBDateTimePicker1.boundsRect:=DBGrid1.SelectedFieldRect;
Editor:=DBDateTimePicker1;
DBDateTimePicker1.Visible:=True;
end;
end;