如何在Delphi中通过Tab或箭头键在字符串网格的单元格之间移动?正如您所知,Delphi中的字符串网格只有一个Tab顺序,但我需要通过箭头键或Tab键在单元格之间移动,以使其更加舒适和用户友好。
我尝试使用KeyPress事件,但是该事件仅知道字符,而不知道像Tab等控制键...
如何在Delphi中通过Tab或箭头键在字符串网格的单元格之间移动?正如您所知,Delphi中的字符串网格只有一个Tab顺序,但我需要通过箭头键或Tab键在单元格之间移动,以使其更加舒适和用户友好。
我尝试使用KeyPress事件,但是该事件仅知道字符,而不知道像Tab等控制键...
StringGrid.Options := StringGrid.Options + [goEditing, goTabs];
或者在设计时设置。
现在,您可以使用Tab和箭头键在单元格之间移动。如果您正在编辑单元格,则必须首先释放焦点,如果想要移动到左侧或右侧的单元格。在这种情况下,请使用(shift) Tab。
{ 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;
Col
属性的新值之前,先将EditorMode := false
。 - Remy Lebeau