菜鸟请求帮忙:在Delphi的DBGrid中,如何方便用户的日期字段的输入及输入后的有效性检查??

xlzps 2001-01-17 04:01:00
希望能提供一个较简单的解决方法!!
不好意思,我刚加入,无分可送,望各位大虾能够谅解!
...全文
253 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwm8246 2001-01-17
  • 打赏
  • 举报
回复
sorry:

在 Dataset的 beforepost 事件中检查
//var str:string;
var str:Tdatetime;
try
str:=strtodate(dataset.fieldbyname('datefield_Name').asstring);
except
dataset.cancel;
showMessage('some error');
abort;
end;
xlzps 2001-01-17
  • 打赏
  • 举报
回复
to Nicky_he(尼克) 
你的方法能否说的详细一点,DBLookupCombo1的属性是否要设置??
xlzps 2001-01-17
  • 打赏
  • 举报
回复
to Nicky_he(尼克) 
用datetimepicker控件替代的方法,在DBEdit中要输入时间时我试过,很好实现!DBGrid中,没有用过,我去试试!!谢谢你们的帮忙!!
xlzps 2001-01-17
  • 打赏
  • 举报
回复
to lwm8246
str:=strtodate(dataset.fieldbyname('datefield_Name').asstring);
这条语句好像不对!

xlzps 2001-01-17
  • 打赏
  • 举报
回复
这样做好像不行吧,
str:=strtodate(dataset.fieldbyname('datefield_Name').asstring);
这条语句好像不对!
Nicky_he 2001-01-17
  • 打赏
  • 举报
回复
放一个datetimepicker控件,
以下是放dbcombox的情形:
1、form.create时 隐藏
dblookupcombo1.visible:=false;
2、
procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState);
begin
if (gdFocused in State) then
begin
if (Field.FieldName = DBLookupCombo1.DataField) then
begin
DBLookupCombo1.Left := Rect.Left + DBGrid1.Left;
DBLookupCombo1.Top := Rect.Top + DBGrid1.top;
DBLookupCombo1.Width := Rect.Right - Rect.Left;
{ DBLookupCombo1.Height := Rect.Bottom - Rect.Top; }
DBLookupCombo1.Visible := True;
end;
end;
end;
3、
procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
If DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField then
DBLookupCombo1.Visible := false;
end;
4、
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (key <> chr(9)) then
begin
if (DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField) then
begin
DBLookupCombo1.SetFocus;
SendMessage(DBLookupCombo1.Handle, WM_Char, word(Key), 0);
end;
end;
end;
把它改动一下就变成datetimepicker了,
不过也可以找别的如rxlib的dbdateedit;
lwm8246 2001-01-17
  • 打赏
  • 举报
回复
在 Dataset的 beforepost 事件中检查
var str:string;
try
str:=strtodate(dataset.fieldbyname('datefield_Name').asstring);
except
dataset.cancel;
showMessage('some error');
abort;
end;

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧