DBGrid实现用回车键就移到下一格,同行完结时,移到下一行 在DBGrid的OnKeyPress的事件里写入代码: 例子如下: procedure TForm.DBGridKeyPress(Sender: TObject; var Key: Char); var n:Integer; begin if Key=#13 then begin Key:=#0; if DBGrid1.SelectedIndex<(DBGrid1.Columns.Count-1) then DBGrid1.SelectedIndex:=n+1 else begin Table1{连接到DBGrid1的数据表}.Append; DBGrideh1.SelectedIndex:=0; end; end; end;
datasouce1.dataset := adoquery1
dbgrid.datasource := datasource1;按回车跳下一行:你先得到当前的行号,比如说是i,然后dbgrid.rows[i].selected := true
不要直接读写dbgrid
在dbgrid的onkeypress中拦截回车按键
当前列在商品编码:则用另一个query到商品信息中查找相应编码的数据
找到了写到当前的query中,然后指定列到数量上
当前列在数量:检查各项数据是否合法,合法就对当前query新增一条记录
不合法给相应提示,然后指定到相应列上指定列tdrawgrid(dbgrid1).col:=xx;
回车的key值13
DBGrid1.Fields[5].FocusControl;
//跳到下一行,并增加一行
在DBGrid1KeyPress事件中,截取到回车信息,并增加一条记录(ADOQuerty1.Append)即可。
在DBGrid的OnKeyPress的事件里写入代码:
例子如下:
procedure TForm.DBGridKeyPress(Sender: TObject; var Key: Char);
var
n:Integer;
begin
if Key=#13 then
begin
Key:=#0;
if DBGrid1.SelectedIndex<(DBGrid1.Columns.Count-1) then
DBGrid1.SelectedIndex:=n+1
else
begin
Table1{连接到DBGrid1的数据表}.Append;
DBGrideh1.SelectedIndex:=0;
end;
end;
end;
我觉得用edit框也能达到同样的效果哟
而且代码也好写的多!