if (key=13) or (key=VK_RIGHT) then begin Key:=0; with RxDbGrid1 do begin if Selectedindex<(FieldCount-1) then selectedindex:=Selectedindex+1{ 移动到下一字段} else Selectedindex:=0; end; end; if key=VK_LEFT then begin Key:=0; with RxDbGrid1 do begin if Selectedindex>1 then //(FieldCount-1) then selectedindex:=Selectedindex-1{ 移动到下一字段} else Selectedindex:=0; end;
大概意思就是楼上这位的,不过在DBGrid中Left和Right键不用写代码 如果是在KeyDown中可以写成 if Key = VK_RETURN then Key := VK_TAB 如果是在KeyPress中稍微麻烦一点 if Key = #13 then if DBGrid1.SelectedIndex < DBGrid1.FieldCount - 1 then DBGrid1.SelectedIndex := DBGrid1.SelectedIndex + 1 else DBGrid1.SelectedIndex := 0; 代码和楼上的朋友差不多,不过DBGrid中的这些属性对不对我也记不太清了,很久没有用DBGrid了。
或者在KeyPress里做判断现在在哪一列,然后增加选择列的序号
Key:=0;
with RxDbGrid1 do begin
if Selectedindex<(FieldCount-1) then
selectedindex:=Selectedindex+1{ 移动到下一字段}
else Selectedindex:=0;
end;
end;
if key=VK_LEFT then begin
Key:=0;
with RxDbGrid1 do begin
if Selectedindex>1 then //(FieldCount-1) then
selectedindex:=Selectedindex-1{ 移动到下一字段}
else Selectedindex:=0;
end;
如果是在KeyDown中可以写成
if Key = VK_RETURN then Key := VK_TAB
如果是在KeyPress中稍微麻烦一点
if Key = #13 then
if DBGrid1.SelectedIndex < DBGrid1.FieldCount - 1 then
DBGrid1.SelectedIndex := DBGrid1.SelectedIndex + 1
else DBGrid1.SelectedIndex := 0;
代码和楼上的朋友差不多,不过DBGrid中的这些属性对不对我也记不太清了,很久没有用DBGrid了。