开发者

delphi : move between cells of string grid

开发者 https://www.devze.com 2023-03-20 12:15 出处:网络
How can I move between cells of a string grid in Delphi by tab or arrow keys? As you know, a string grid in delphi has only one tab order but I need to move between cells by arrow keys or tab to be mo

How can I move between cells of a string grid in Delphi by tab or arrow keys? As you know, a string grid in delphi has only one tab order but I need to move between cells by arrow keys or tab to be more comfortable and user friendly .

I tried to use a KeyPress event, but this event only knows chars and doesn't know开发者_C百科 control keys like tab and ...


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

Or set this designtime.

Now you can move from cell to cell with tab and arrow keys. If you are actually editing a cell, then you have to release the focus first if you want to move to the cell to the left or right. In that case, use (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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号