Autor Beitrag
ThomasQ
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: So 20.01.13 03:07 
Hallo,

ich stehe vor folgendem Problem: Durch die Aktivierung von "goRowSelect" (Grund ist die beabsichtigte Anzeige der Selektionszeile) 'weiß' mein Programm nunmehr nicht mehr, in welcher Spalte sich der Mauszeiger bei einem Click befand. Für den weiteren Programmablauf wird aber dieser Wert benötigt.

Wie erhalte ich dennoch den Wert für die Spalte?

Vielen Dank bereits jetzt schon!!!
Tranx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 648
Erhaltene Danke: 85

WIN 2000, WIN XP
D5 Prof
BeitragVerfasst: So 20.01.13 07:04 
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.

ausblenden volle Höhe Delphi-Quelltext
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;              // StringGrid
    buganzeZeile: TBitBtn;         // Button 1
    buZelle: TBitBtn;              // Button 2
    Label1: TLabel;                // Label (Caption: Spalte)
    e1: TEdit;                     // Editfeld
    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);
    { Private-Deklarationen }
  public
    property AktCol : integer Read GetAktCol write SetAktCol;
    property GanzeZeile : boolean read GetGanzeZeile write SetGanzeZeile;
    { Public-Deklarationen }
  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 // nur setzen, wenn nicht gleich dem gespeicherten Wert
  begin
    if Value then  // bei Auswahl der ganzen Zeile erst aktuelle Spalte zwischenspeichern
    begin
      AktCol := sg1.Col;
      sg1.Options := sg1.Options + [goRowSelect];
    end
    else
    begin
      sg1.Options := sg1.Options - [goRowSelect];
      sg1.Col := AktCol; // ... und bei Zellauswahl wieder zurückholen
    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.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: So 20.01.13 18:46 
Hallo,

user profile iconThomasQ hat folgendes geschrieben Zum zitierten Posting springen:
Aktivierung von "goRowSelect" (Grund ist die beabsichtigte Anzeige der Selektionszeile)
Wenn das der einzige Grund ist, bleibt natürlich immer noch die Variante die Zellen selbst zu zeichnen. Stichwort für die Suche: "Zellen einfärben".
Dann lässt du einfach die Zellselektion wie sie ist, und malst alles was in der gleichen Zeile wie die Fokussierte in einer Farbe (und evtl. die aktuelle Spalte noch in einer anderen).

Viele Grüße,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
ThomasQ Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32



BeitragVerfasst: So 20.01.13 20:42 
Vielen Dank für die Antworten!

Das Grundprinzip (Aufhebung 'goRowSelect' - Ermittlung sgStringGrid.Col - Reaktivierung 'goRowSelect') habe ich verstanden und so mit Hilfe des ersten Beitrags das Problem lösen können!

Prima, wie hier geholfen wird!!!