因为 引用 CheckBox1不要 双击后,出现 0的Edit显示 所以,去掉 dgEditing
DBGrid1.Options:= DBGrid1.Options-[ dgEditing];
所有DBGrid1的Editor控件,事件 都 要自己写,包括 默认Edit
procedure TForm13.DBGrid1ColExit(Sender: TObject); // 退出 时,不显示 编辑 控件 begin if DBGrid1.SelectedField.FieldName = 'aedit' then edit1.Visible := False; end; //============================================================= === procedure TForm13.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); const CtrlState: array [Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED); // CheckBox1 列 要用到的 begin if (gdFocused in State) then begin if (Column.Field.FieldName = 'aedit') then with edit1 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; edit1.Text:= Column.Field.AsString; // 数据 传给 Edit1 Visible := True; end; end; end; //============================================================= === procedure TForm13.DBGrid1KeyPress(Sender: TObject; var Key: Char); // 将 DBGrid1的键盘 信息传 给 edit1 begin if (Key = Chr(9)) then Exit; //TAB 键 直接退出 //==============================edit1===================================== if (DBGrid1.SelectedField.FieldName = 'aedit') then begin edit1.SetFocus; SendMessage(edit1.Handle, WM_Char, word(Key), 0); end; end; //===================================================== procedure TForm13.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key = Chr(13)) then begin edit1.Visible := False; DBGrid1.DataSource.Edit; DBGrid1.SelectedField.Value := edit1.Text; FDQuery1.Post; end; end; //===========================================================