如题,scrollbars: ssboth; rowselect选中的情况下,按左,右方向键时只能上下移动,怎么才能只移动水平滚动条?

解决方案 »

  1.   

    给你一段代码!unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Grids, StdCtrls;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
          Shift: TShiftState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      i,j : Integer;
    begin
      StringGrid1.RowCount := 100;
      StringGrid1.ColCount := 100;  for i:=0 to StringGrid1.RowCount -1 do
        for j:=0 to StringGrid1.ColCount -1 do
          StringGrid1.Cells[i,j] := IntToStr(i*j);
    end;procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    begin
      if Key = VK_LEFT then
      begin
        Sendmessage(StringGrid1.Handle, WM_HSCROLL, SB_PAGELEFT, 0);
        Key:=0;
      end;  if Key= VK_RIGHT then
      begin
        Sendmessage(StringGrid1.Handle, WM_HSCROLL, SB_PAGERIGHT, 0);
        Key:=0;
      end;
    end;end.