Announcement

Collapse
No announcement yet.

Im TStringGrig mit Enter-Taste eine Zelle weiter

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Im TStringGrig mit Enter-Taste eine Zelle weiter

    Hi,

    wie kann ich in einem StringGrid nach einer Eingabe mit der Enter-Taste eine Zelle weiterkommen.

    Danke
    Iris

  • #2
    Hallo Iris

    hier ein Beispiel, das funktioniert

    <Pre>

    unit Unit1;

    interface

    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Grids;

    type

    TForm1 = class(TForm)

    StringGrid1: TStringGrid;

    procedure GotoNextCell(sGrid: TStringGrid); // mußt du per Hand einfügen

    procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);

    private

    { Private-Deklarationen }

    public

    { Public-Deklarationen }

    end;

    var

    Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.GotoNextCell(sGrid: TStringGrid);

    var

    sRect: TGridRect;

    begin

    sRect := sGrid.Selection;

    if sRect.Left < sGrid.ColCount - 1 then inc(sRect.Left,1)

    else if sRect.Top < sGrid.RowCount - 1 then

    begin

    inc(sRect.Top,1) ;

    sRect.Left := 1;

    end;

    sRect.Bottom := sRect.Top;

    sRect.Right := sRect.Left;

    sGrid.Selection := sRect;

    end;

    procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);

    begin

    if Key = #13 then GotoNextCell(StringGrid1);

    end;

    end.

    </Pre>

    Soll man ja nicht machen, aber wenn's denn sein soll. Du engst Dich damit unnötig ein.

    Gruß
    Bernhard :

    Comment


    • #3
      Hallo Iris,<p>
      versuch es mal mit:<p><PRE>
      procedure TForm1.RStringGrid1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
      begin
      if Key = 13 then begin
      if RStringGrid1.Col < RStringGrid1.ColCount - 1 then begin
      RStringGrid1.Col := RStringGrid1.Col + 1;
      end
      else begin
      RStringGrid1.Col := RStringGrid1.FixedCols;
      if RStringGrid1.Row < RStringGrid1.RowCount - 1 then begin
      RStringGrid1.Row := RStringGrid1.Row + 1;
      end
      else begin
      RStringGrid1.Row := RStringGrid1.FixedRows;
      end;
      end;
      end;
      end;
      </PRE>
      Im KeyDown-Ereignis wird die Taste abgefragt.<p>
      Gruß<p>
      Wolfgang Rolle

      Comment

      Working...
      X