Autor Beitrag
hansg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Di 04.03.08 07:06 
Hallo zusammen,
ich habe folgendes Problem:
Ich nutze ein Stringgrid und möchte verhindern das man einen Bereich markieren kann
wenn keine Einträge in der Liste vorhanden sind.
Sind keine da soll die Markierung wieder weggenommen werden und eine bestimmte Zelle (Reihe 1 / Zeile 1) markiert werden.
Irgendwie komme ich nicht weiter, mal funktioniert es manchmal nicht.
Hier mal mein Versuch:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if liste <1 then   // Keine Einträge da
  begin
    stringgrid1.Options:= stringgrid1.Options - [goRowSelect];
    stringgrid1.Row:=1;
    stringgrid1.col:=1;
  end
  else
  begin
    // Anweisungen wenn Einträge vorhanden
  end;
end;

_________________
Gruß Hans
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Di 04.03.08 13:24 
Ändere doch bei jeder Änderung die Eigenschaft Enabled. Dann kann man gar nichts mehr machen. Das ist übrigens auc die "echte" Lösung, alles andere wäre gebastelt.
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Mi 05.03.08 07:10 
Hallo,

danke für den Tip, das mit dem enablen funktioniert aber nicht so richtig.
Sobald ich das auf false setzte wird immer die 1. Zeile / Spalte blau markiert.
Habe mal zum Test auf leeres Formular ein Grid aufgesetzt, da verhält es sich genau so.
Wie kriege ich das denn weg?

_________________
Gruß Hans
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 06.03.08 15:26 
Hallo,

schau Dir mal das Ereignis OnSelectCell und die zugehörige Prozedurvariable CanSelect des Stringgrids an.
Damit kannst Du verhindern das selectiert wird.

z.B.:
ausblenden Delphi-Quelltext
1:
2:
if liste < 1 then
  CanSelect := False;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Sa 08.03.08 10:51 
Funktioniert leider nicht,
ich kann immer noch das Grid markieren, sonts noch jemand einen Tip?

_________________
Gruß Hans
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 08.03.08 19:47 
Hallo,

nehm an das in Deinen StringGrid.Options noch goRangeSelect enthalten ist.
:arrow: goRangeSelect ist ungleich goRowSelect

Das funktioniert:
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:
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    StringGrid1: TStringGrid;
    procedure StringGrid1SelectCell(Sender: TObject; Col, Row: Integer;
      var CanSelect: Boolean);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  Liste : Integer;
implementation

{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
  StringGrid1.Options := StringGrid1.Options - [goRangeSelect];
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; Col, Row: Integer;
  var CanSelect: Boolean);
begin
  if Liste < 1 then
    begin
    StringGrid1.Options:= StringGrid1.Options - [goRowSelect];
    StringGrid1.Selection := TGridRect(Rect(1,1,1,1));
    CanSelect := False;
    end
    else
      StringGrid1.Options:= StringGrid1.Options + [goRowSelect];
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Liste := 0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Liste := 3;
end;
end.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Sa 08.03.08 22:02 
Hallo,

danke für die Hilfe, funktioniert soweit.
Da ich nicht nur den Quelltext kopieren sondern auch verstehen will, was bewirkt folgende Anweisung?

ausblenden Delphi-Quelltext
1:
  StringGrid1.Selection := TGridRect(Rect(1,1,1,1));					

_________________
Gruß Hans
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Sa 08.03.08 22:10 
user profile iconhansg hat folgendes geschrieben:
was bewirkt folgende Anweisung?

ausblenden Delphi-Quelltext
1:
  StringGrid1.Selection := TGridRect(Rect(1,1,1,1));					

Damit wird die oberste linke Zelle markiert.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mo 10.03.08 20:22 
Hallo,

user profile iconYogu hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
  StringGrid1.Selection := TGridRect(Rect(1,1,1,1));					

Damit wird die oberste linke Zelle markiert.
nee, :wink:
dann müsste es so sein:
ausblenden Delphi-Quelltext
1:
StringGrid1.Selection := TGridRect(Rect(0,0,0,0));					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
hansg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 168

Win XP Professional SP3, Vista Ultimate 32 SP1
Delphi 6 Professional
BeitragVerfasst: Mo 10.03.08 21:13 
user profile iconLannes hat folgendes geschrieben:
Hallo,

user profile iconYogu hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
  StringGrid1.Selection := TGridRect(Rect(1,1,1,1));					

Damit wird die oberste linke Zelle markiert.
nee, :wink:
dann müsste es so sein:
ausblenden Delphi-Quelltext
1:
StringGrid1.Selection := TGridRect(Rect(0,0,0,0));					


Schön,

könnte mir das mal bitte einer erklären was die Anweisung genau bedeutet?

_________________
Gruß Hans
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 11.03.08 00:21 
Hallo,

dann wollen wir mal :wink:

Wenn Du im Editor den Cursor in eine Funktion, Eigenschaft u.a. setzt und die Taste [F1] bemühst, kommst Du direkt an die richtige Stelle in der Delphi-Hilfe.

Dort findest Du dann die folgende Deklaration der Eigenschaft Selection:
ausblenden Delphi-Quelltext
1:
property Selection: TGridRect;					
Will man der Eigenschaft Selection etwas zuweisen, muss es vom Typ TGridRect sein.
Eine Zuweisung in der Art funktioniert daher nicht:
ausblenden Delphi-Quelltext
1:
Selection := (0,0,0,0);					


Rect ist eine Funktion zur Typumwandlung und gibt den Datentyp TRect mit den gesetzten Parametern zurück. Das TRect wird dann wiederum durch eine Typumwandlung mit TGridRect() in den Datentyp verwandelt den die Eigenschaft Selection erfordert.

Der Datentyp TGridRect ist ein sogenannter varianter Record.

Mittels Selection und Typumwandlungen kann man eine Zelle oder auch einen Bereich in einem Grid mit nur einer Codezeile auswählen.

Um das mal zu verdeutlichen nun die Selection eines Bereichs in einem Grid ohne Typumwandlungen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var aGridRect : TGridRect;
begin
  aGridRect.Left := 1;
  aGridRect.Top := 1;
  aGridRect.Right := 3;
  aGridRect.Bottom := 3;
  StringGrid1.Selection := aGridRect;


Für noch mehr Informationen kannst Du Dich in den diversen zur Verfügung stehenden Quellen mit den Begriffen "Variante Records", "Typumwandlung" oder "Typecast" umsehen.

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )