Soweit ich das gesehen habe, ist das ein normales Verhalten. Wenn Du die aktuelle Spalte behalten willst, musst Du sie zwischenspeichern. Eine Möglichkeit ist die property (siehe meinen Quelltext). Hierbei habe ich zwei Buttons, einen Label, ein Editfeld und ein Stringgrid auf dem Formular.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91:
| unit SelectUnit;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, Grids;
type TForm1 = class(TForm) sg1: TStringGrid; buganzeZeile: TBitBtn; buZelle: TBitBtn; Label1: TLabel; e1: TEdit; procedure buganzeZeileClick(Sender: TObject); procedure buZelleClick(Sender: TObject); procedure sg1Click(Sender: TObject); private fGanzeZeile : boolean; fAktCol : integer; function GetAktCol: integer; procedure SetAktCol(const Value: integer); function GetGanzeZeile: boolean; procedure SetGanzeZeile(const Value: boolean); public property AktCol : integer Read GetAktCol write SetAktCol; property GanzeZeile : boolean read GetGanzeZeile write SetGanzeZeile; end;
var Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.buganzeZeileClick(Sender: TObject); begin GanzeZeile := TRUE; e1.Text := IntToStr(AktCol); end;
procedure TForm1.buZelleClick(Sender: TObject); begin GanzeZeile := FALSE; e1.Text := IntToStr(AktCol); end;
function TForm1.GetAktCol: integer; begin Result := fAktCol; end;
function TForm1.GetGanzeZeile: boolean; begin Result := fGanzeZeile; end;
procedure TForm1.SetAktCol(const Value: integer); begin fAktCol := Value; end;
procedure TForm1.SetGanzeZeile(const Value: boolean); begin if Value <> fGanzeZeile then begin if Value then begin AktCol := sg1.Col; sg1.Options := sg1.Options + [goRowSelect]; end else begin sg1.Options := sg1.Options - [goRowSelect]; sg1.Col := AktCol; end; fGanzeZeile := Value; end; end;
procedure TForm1.sg1Click(Sender: TObject); begin sg1.Options := sg1.Options - [goRowSelect]; e1.Text := IntToStr(sg1.Col); end;
end. |
Der Nebeneffekt: Bei Änderung der Eigenschaft Options auf Zellselektion wird die Spalte wieder angewählt.
Ich hoffe, das ist das, was Du wünschst.
Gruß
Gunther
Toleranz ist eine Grundvoraussetzung für das Leben.