请问如何按Enter键让DBGrid的光标向右移以及换行?(0分)

我试了一下,发现DBGrid对Enter键不响应?怎么解决呢?请高手指点!

Form->KeyPreview==true;
寫在Form Down 里
if (Key==VK_RETURN)
Key=Tab;

DBGrid里面的属性option不是有一个设置选项的呵!

在DbGrid的KeyDown中
if Key = 13 then
begin
Key:=0;
if DbGrid1.SelectedIndex<DbGrid1.Columns.Count-1 then
DbGrid1.SelectedIndex:=DbGrid1.SelectedIndex+1 
else
begin
DbGrid1.DataSource.Dataset.next;
DbGrid1.SelectedIndex:=0;
end;
end

在ONKEYPRESS中
if key=#13 then
if not (ActiveControl is TDbgrid) Then
Begin
key:=#0;
perform(WM_NEXTDLGCTL,0,0);
end
else
if (ActiveControl is TDbgrid) Then
begin
With TDbgrid(ActiveControl) Do
if Selectedindex<(FieldCount-1) then
Selectedindex:=Selectedindex+1
else Selectedindex:=0;
end;

在dbgrid的keypress事件中:
if key =#13 then
keybd_event(VK_TAB,0,0,0);

procedure Tform1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
if DBGrid1.SelectedIndex <> DBGrid1.Columns.Count -1 then
DBGrid1.SelectedIndex := DBGrid1.SelectedIndex + 1
else
DBGrid1.SelectedIndex :=0;
end

在Form的keypress中﹕
if Key = #13 then
begin
if not (Activecontrol is TDBGrid) then
begin
Key:=#0;
Selectnext(Twincontrol(Activecontrol),True,True);
end
else
if (Activecontrol is TDBGrid) then
begin
with TDBGrid(Activecontrol) do
if Selectedindex<(Fieldcount-1) then
Selectedindex:= Selectedindex+1
else
Selectedindex:=0;
end;
end
else
if Key = #27 then self.Close;

請試一下(在DBGRID1的KeyPress事件中):
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if Key=#13 then
Begin
SendMessage(DBGrid1.handle,WM_KEYDOWN,VK_TAB,0);
Key:=#0;
End;
end;

好的代码像粥一样,都是用时间熬出来的
原文地址:https://www.cnblogs.com/jijm123/p/13658118.html