Delphi:在字符串网格的单元格之间移动

5

如何在Delphi中通过Tab或箭头键在字符串网格的单元格之间移动?正如您所知,Delphi中的字符串网格只有一个Tab顺序,但我需要通过箭头键或Tab键在单元格之间移动,以使其更加舒适和用户友好。

我尝试使用KeyPress事件,但是该事件仅知道字符,而不知道像Tab等控制键...


关于错误:http://meta.stackexchange.com/questions/92074/what-can-i-do-when-getting-it-does-not-meet-our-quality-standards - Mikael Eriksson
2个回答

5
StringGrid.Options := StringGrid.Options + [goEditing, goTabs];

或者在设计时设置。

现在,您可以使用Tab和箭头键在单元格之间移动。如果您正在编辑单元格,则必须首先释放焦点,如果想要移动到左侧或右侧的单元格。在这种情况下,请使用(shift) Tab。


goediting 用于在单元格中输入文本,如果为 false,则无法在单元格中输入。 - Arash

0
{ This handles arrow left and right in the GRID
}
procedure TJournalForm.JournalGridKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);

begin
    if (JournalGrid.EditorMode = True) then      //  if arrowing while editing…
      begin
           if Key=VK_Left then if JournalGrid.Col>(JournalGrid.FixedCols+1) then JournalGrid.Col:=JournalGrid.Col-1;
         if Key=VK_Right then if JournalGrid.Col<(JournalGrid.ColCount-1) then JournalGrid.Col:=JournalGrid.Col+1;
    end;
end;

1
在设置Col属性的新值之前,先将EditorMode := false - Remy Lebeau

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接