قراردادن DateTimePicker در یک DBGrid:
ابتدا کد زیر را
در قسمت رویداد OnDrawColumnCell وارد نمایید:
procedure
TForm1.DBGrid1DrawColumnCell
(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumn;
State:
TGridDrawState);
begin
if (gdFocused in State)
then
begin
if
(Column.Field.FieldName = 'YourDateField')
then
with DateTimePicker do
begin
Left :=
Rect.Left + DBGrid1.Left + 1;
Top := Rect.Top
+ DBGrid1.Top + 1;
Width :=
Rect.Right - Rect.Left + 2;
Width :=
Rect.Right - Rect.Left + 2;
Height := Rect.Bottom - Rect.Top +
2;
Visible :=
True;
end;
end
end;
سپس در ادامه این
کد را در رویداد OnColExit بنویسید:
procedure
TForm1.DBGrid1ColExit(Sender: TObject);
begin
if
DBGrid1.SelectedField.FieldName = 'YourDateField' then
DateTimePicker.Visible :=
False
end;
و در نهایت در
رویداد OnKeyPress بنویسید:
procedure
TForm1.DBGrid1KeyPress
(Sender: TObject; var
Key: Char);
begin
if (key = Chr(9)) then
Exit;
if
(DBGrid1.SelectedField.FieldName = 'YourDateField')
then
begin
DateTimePicker.SetFocus;
SendMessage(DateTimePicker.Handle, WM_Char, word(Key),
0);
end
end;