DateTimePicker in DBGrid - keyboard controll lazarus / 16-Databases ---------------------------------------------------------------------- Joek · 2021-03-23 09:11 Forgive the novice for a stupid question and bad English (google translator opened the door to the English world for me). I use DateTimePicker as a date editor in DBGrid. When controlling the mouse, everything is OK, but if I press the Esc, Enter keys, the Tab DateTimePicker ends and the subsequent transition to any DBgrid cell causes the cell contents to be reset (it is empty). The data is OK - the doubleclick on the cell reads its data back and everything is OK. Trying to capture the Enter key (I'm attaching the code) doesn't solve the problem. I don't know where the mistake is. Can anyone show me the direction? Next question: Is it possible to catch the date of the date selection date in the DateTimePicker? I don't mean Change - it also responds to the keyboard. Or could it be done on a doubleclick (as in DBDateEdit)?Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  procedure TFrmOhlaseni.DateTimePicker1Change(Sender: TObject); begin    //if DBGrid1.DataSource.State in [dsEdit, dsInsert] then    //if DBGrid1.DataSource.State in dsEditModes then    //begin    //  DBGrid1.SelectedField.Value := DateTimePicker1.Date;    //end;    DBGrid1.DataSource.Edit;    DBGrid1.SelectedField.Value := DateTimePicker1.Date; end; procedure TFrmOhlaseni.DateTimePicker1DblClick(Sender: TObject); begin    DBGrid1.DataSource.DataSet.Post; end; procedure TFrmOhlaseni.DateTimePicker1EditingDone(Sender: TObject); begin    DateTimePicker1.Hide; end; procedure TFrmOhlaseni.DateTimePicker1KeyPress(Sender: TObject; var Key: char); begin      if Key = #13 then       //Enter      begin         DBGrid1.DataSource.Edit;         DBGrid1.SelectedField.Value := DateTimePicker1.Date;         DateTimePicker1.Hide;      end; end; ---------------------------------------------------------------------- Joek · 2021-03-23 09:15 Sorry for the incorrect code entry. Here it is:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [procedure TFrmOhlaseni.DBGrid1SelectEditor(Sender: TObject; Column: TColumn;  var Editor: TWinControl);begin   //if Column.Index = 2 then begin   if (DBGrid1.SelectedField.FieldName = 'DATE_ZAHAJENI') then  begin     DateTimePicker1.BoundsRect:=DBGrid1.SelectedFieldRect;     DateTimePicker1.Date := DBGrid1.SelectedField.AsDateTime;     Editor:=DateTimePicker1;   end;end; procedure TFrmOhlaseni.DateTimePicker1Change(Sender: TObject);begin   //if DBGrid1.DataSource.State in [dsEdit, dsInsert] then   //if DBGrid1.DataSource.State in dsEditModes then   //begin   //  DBGrid1.SelectedField.Value := DateTimePicker1.Date;   //end;   DBGrid1.DataSource.Edit;   DBGrid1.SelectedField.Value := DateTimePicker1.Date;end; procedure TFrmOhlaseni.DateTimePicker1DblClick(Sender: TObject);begin   DBGrid1.DataSource.DataSet.Post;end; procedure TFrmOhlaseni.DateTimePicker1EditingDone(Sender: TObject);begin   DateTimePicker1.Hide;end; procedure TFrmOhlaseni.DateTimePicker1KeyPress(Sender: TObject; var Key: char);begin     if Key = #13 then       //Enter     begin        DBGrid1.DataSource.Edit;        DBGrid1.SelectedField.Value := DateTimePicker1.Date;        DateTimePicker1.Hide;     end;end; ] ---------------------------------------------------------------------- Joek · 2021-03-24 07:11 I will answer myself: Most problems are solved by using the DBDateTimePicker component set to the same DataSource as the DBGrid. And also set the DataField correctly of course. The code for use in DBGrid is then very simple. Please close the topic.Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFrmOhlaseni.DBGrid1SelectEditor(Sender: TObject; Column: TColumn;  var Editor: TWinControl);begin   if (DBGrid1.SelectedField.FieldName = 'DATE_ZAHAJENI') then  begin     DBDateTimePicker1.BoundsRect:=DBGrid1.SelectedFieldRect;     Editor:=DBDateTimePicker1;   end;end;