Autor Beitrag
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: So 04.05.03 20:49 
Hi,

angenommen, ich habe ein Stringgrid mit nur einer Zeile und 5 Spalten. Bin ich in der letzten Spalte und gebe dort etwas ein, soll eine neue leere Zeile erzeugt werden. Also nur, wenn ein Wert eingegeben wurde und der Befehl zum Verlassen dieser Spalte eingegeben wurde. Die anderen Spalten sollen Read/Only sein. Tja, dazu fällt mir nichts ein. Anscheinend gibt es so was wie "OnCellExit" nicht.

_________________
Gruß
Hansa
Blackout
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 64



BeitragVerfasst: So 04.05.03 21:28 
hi hansa,
also mit dem Ereignis SetEditText kannst du das machen. Probier mal das hier:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
  ARow: Integer; Const Value: String);
Begin

 
  If (ARow= StringGrid1.RowCount-1) Then
    If Value<> '' Then StringGrid1.RowCount:= StringGrid1.RowCount+1;


End;


So un meine Pizza is auch da :D

_________________
MfG Blackout
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: So 04.05.03 21:37 
Auch wenn ich gerade bezweifle, dass diese Lösung funktioniert: Man kanns auch kürzer schreiben:
ausblenden Quelltext
1:
If (ARow= StringGrid1.RowCount-1) AND (Value<> '') Then StringGrid1.RowCount:= StringGrid1.RowCount+1;					


Hab aber gerade keine Zeit es zu probieren, geschweige denn zu testen:wink:
Blackout
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 64



BeitragVerfasst: So 04.05.03 22:01 
@UGrohne
Das ist genau das gleiche :D

@Hansa
hier so funktionierts mit ReadOnly:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
// SetEditText Ereignis

Procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol,
  ARow: Integer; Const Value: String);
Begin

  If (ARow= StringGrid1.RowCount-1) AND (Value<> '') Then StringGrid1.RowCount:= StringGrid1.RowCount+1;
  // Optimiert bei UGrohne ;-)

End;



// OnClick Ereignis ReadOnly nur bei letzter Zeile aufheben

Procedure TForm1.StringGrid1Click(Sender: TObject);
Begin

  If (StringGrid1.Row= StringGrid1.RowCount-1) Then
    StringGrid1.Options:= StringGrid1.Options+[goEditing]
  Else StringGrid1.Options:= StringGrid1.Options-[goEditing];

End;


Klappt :D

_________________
MfG Blackout
I_Z_U_A_L
Hält's aus hier
Beiträge: 15



BeitragVerfasst: So 04.05.03 22:27 
Funktioniert super ;)
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: So 04.05.03 23:27 
Blackout hat folgendes geschrieben:
@UGrohne
Das ist genau das gleiche :D

Ja, hab ja auch dazu geschrieben, dass das nur die kürzere Variante sei. :wink:

Gruß
hansa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: So 04.05.03 23:52 
I_Z_U_A_L hat folgendes geschrieben:
Funktioniert super ;)


Das ist meine Frage! :angel: Wo war denn bei Dir die Fragestellung, oder woran hings?

_________________
Gruß
Hansa
hansa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mo 05.05.03 10:05 
das geht doch noch nicht richtig. Das value enthält den Wert des letzten Feldes, deshalb wird auch eine neue Zeile eingefügt, wenn nichts in dem Feld steht.

_________________
Gruß
Hansa
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mo 05.05.03 11:05 
Hallo wenn du mit setedittext arbeitest, wird immer eine neue zeile angehängt, auch wenn du nur eine Taste drückst.
ich würds so machen (mit onselectcell :wink: , paßt auch zu deinem anderen Problem :wink:)

ausblenden volle Höhe 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:
  private der Form
    { Private-Deklarationen }
    Foldrow, Foldcol:integer;  //letzte Zellen position
...

...

procedure TForm1.FormCreate(Sender: TObject);
begin
  Foldrow:=0;
  foldcol:=0;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  with sender as TStringGrid do
    begin
      if (foldcol=colcount-1) and (foldrow=rowcount-1) and (cells[foldcol,foldrow]<>'') then rowcount:=rowcount+1;
      foldrow:=arow;
      foldcol:=acol;
    end;
end;

procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  //und auch wenn enter gedrückt wird
  with sender as tstringgrid do
  if key=vk_return then if (col=colcount-1) and (row=rowcount-1) and (cells[col,row]<>'') then rowcount:=rowcount+1;
end;


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
hansa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mo 05.05.03 13:03 
Hi,

Keldorns Methode geht einwandfrei. Ich drucke mir die mal aus, um zu sehen was da genau abläuft. Die neue Zeile wird bei Bedarf eingefügt, aber, wie kriege ich den Cursor dann automatisch in die nächste Zeile ? Der hängt immer noch in dem Feld fest.

_________________
Gruß
Hansa
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mo 05.05.03 13:21 
hansa hat folgendes geschrieben:
Hi,

Keldorns Methode geht einwandfrei. Ich drucke mir die mal aus, um zu sehen was da genau abläuft.

:oops: mir sind ist da die Formatierung flöten gegangen.
Eigentlich nur zwei sachen laufen: im Onselect prüfst du ob eine neue Zelle angeklickt oder per cursor ausgewählt wird und wenn die letzte Zelle die rechte untere Zelle war, wird halt eine neue Zeile drangehangen.

im Onkeydown prüfst du, ob enter gedrückt wurde und wenn es wieder die rechte untere Zelle war, dann kommt auch wieder ne neue Zeile hinten dran.

Es kommt drauf an, was du erreichen willst.

Zitat:

Die neue Zeile wird bei Bedarf eingefügt, aber, wie kriege ich den Cursor dann automatisch in die nächste Zeile ? Der hängt immer noch in dem Feld fest.


beim onkeydown kein Problem:
beim onselect machts evtl. keinen sinn.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  with sender as tstringgrid do
    if key=vk_return then
      if (col=colcount-1) and (row=rowcount-1) and (cells[col,row]<>'') then
        begin
          rowcount:=rowcount+1;
          row:=rowcount-1;
          col:=1;
        end;
end;


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Mo 05.05.03 13:26 
halt, da fällt mir ein, es geht noch kürzer. Foldrow und col brauchst du ja garnicht.
Arow und Acol beim selectcell sind ja die neuen Koordinaten der neu gewählten Zelle, also sind col und row noch die alten Koordinaten.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  with sender as TStringGrid do
    begin
      if (col=colcount-1) and (row=rowcount-1) and (cells[col,row]<>'') then
        rowcount:=rowcount+1;
    end;
end;

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Blackout
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 64



BeitragVerfasst: Mo 05.05.03 13:37 
@hansa
dann haste bestimmt das OnClick ereignis vergessen :)
Er fügt immer nur ne neue Zeile ein wenn etwas in der letzten reingeschreiben wird, also bei mir funktionierts :wink:

_________________
MfG Blackout
hansa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Mo 05.05.03 14:29 
Ich mußte noch ein paar mal die Politur benutzen. Den Quelltext habe ich jetzt schon dreimal ausgedruckt. 8) Jetzt nehm ich den letzten Ausdruck mal mit und lese ihn genau durch, beim Eis. :lol:

_________________
Gruß
Hansa