1、首先用(商品编码,商品名称,规格,单位)建立一个字典库,然后再建立一个(商品编码,进价,数量)数据库,可以建立“商品编码”为关键字的索引,设置(商品编码,商品名称,规格,单位)的商品编码为主索引。 2、代码 procedure TForm1.FormCreate(Sender: TObject); begin //消息循环 Application.OnMessage := AppMessage; end;procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean); begin if (Msg.message = WM_KeyDown) and not (ActiveControl is TDBMemo) and not (ActiveControl is TButton) and not (ActiveControl is TComboBox) then if (Msg.wParam = 13) or (Msg.wParam = 40) then begin if not (ActiveControl is TDBGrid) then Perform(Wm_NextDlgCtl, 0, 0) else if (Msg.wParam <> 40) then begin if TDBGrid(ActiveControl).SelectedIndex < (TDBGrid(ActiveControl).FieldCount - 1) then TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1 else TDBGrid(ActiveControl).SelectedIndex := 0; end; end else begin if (Msg.wParam = 38) then if not (ActiveControl is TDBGrid) then Perform(Wm_NextDlgCtl, 1, 0); end; end; 这是回车键响应的代码,数据库代码写在TForm1.AppMessage中就可以了,应该很简单,自己动动脑吧,呵呵!
代码不是colums.setfucos!好像是这样的,可以社在那个cell中设置焦点
2、代码
procedure TForm1.FormCreate(Sender: TObject);
begin
//消息循环
Application.OnMessage := AppMessage;
end;procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if (Msg.message = WM_KeyDown) and not (ActiveControl is TDBMemo) and not (ActiveControl is TButton) and not (ActiveControl is TComboBox) then
if (Msg.wParam = 13) or (Msg.wParam = 40) then begin
if not (ActiveControl is TDBGrid) then
Perform(Wm_NextDlgCtl, 0, 0)
else
if (Msg.wParam <> 40) then begin
if TDBGrid(ActiveControl).SelectedIndex < (TDBGrid(ActiveControl).FieldCount - 1) then
TDBGrid(ActiveControl).SelectedIndex := TDBGrid(ActiveControl).SelectedIndex + 1
else TDBGrid(ActiveControl).SelectedIndex := 0;
end;
end else begin
if (Msg.wParam = 38) then
if not (ActiveControl is TDBGrid) then
Perform(Wm_NextDlgCtl, 1, 0);
end;
end;
这是回车键响应的代码,数据库代码写在TForm1.AppMessage中就可以了,应该很简单,自己动动脑吧,呵呵!