【问题标题】:delphi : move between cells of string griddelphi:在字符串网格的单元格之间移动
【发布时间】:2011-07-13 12:24:03
【问题描述】:

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

我尝试使用 KeyPress 事件,但该事件只知道字符,不知道控制键,如 tab 和 ...

【问题讨论】:

标签: delphi tab-ordering


【解决方案1】:
StringGrid.Options := StringGrid.Options + [goEditing, goTabs];

或者设置这个设计时间。

现在您可以使用制表键和箭头键从一个单元格移动到另一个单元格。如果您实际上正在编辑一个单元格,那么如果您想向左或向右移动到该单元格,则必须先释放焦点。在这种情况下,请使用 (shift) 选项卡。

【讨论】:

【解决方案2】:
{ 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
猜你喜欢
  • 2017-07-18
  • 1970-01-01
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多