Autor Beitrag
Hochhäusl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: Sa 06.09.03 18:57 
Hallo,

ich habe einige Fragen zu Stringgrids:

1. Wie kann ich die ganze Tabelle in eine Datei speichern, nicht nur einen einzelne Zeile/Spalte mit rows[0].savetofile(' '); ?

2. Kann man die Farbe nur einzelner Felder ändern?
(Zum Beispiel alle Felder mit Ziffern die größer als 0 sind grün, alle anderen x<0 gleich rot etc.)

3. onclick-ereignis:?
Die Ziffern der 1. Zeile und Spalte 1,2,3 [1,1 : 1,2 ; 1,3] sollen addiert werden und in das feld Zeile1/Spalte6 ausgegeben werden.
Das ganze für 3 oder 4 Zeilen. :roll:

hoffentlich sind alle Fragen verständlich und ihr könnt mir weiterhelfen
vielen Dank im voraus
Hochhäusl

Moderiert von user profile iconTino: Topic verschoben.
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: Sa 06.09.03 19:14 
Erstell das nächste mal für jdede Frage einen extra thread.

1. www.tipps.delphi-sou.../tut20010805-6.shtml

2. www.tipps.delphi-sou.../tut20020914-1.shtml
sowie Forensuche Suche in: Delphi-Forum, Delphi-Library ONDRAWCELL mit acol,arow bekommst du die zelle, und kannst mit Cells[acol,arow] den Wert abfragen und entsprechend reagieren.

3. du könntest die entsprechenden Zelle mit einer Schleife durchlaufen und die Zellwerte mit Strtoint in Zahlen wandeln und damit rechnen. Wenn die Zelle keine Zahl enthält, bekommst du eine exception, such mal hier im Forum/onlinehilfe nach Suche in: Delphi-Forum, Delphi-Library STRTOINT und Suche in: Delphi-Forum, Delphi-Library STRTOINTDEF. Es gibt vviele Threads, die sich mit dem umwandeln von Strings in Zahlen befassen, einfach mal suchen.

mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
G-man
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 258

Win 2000, Win ME, SuSE 8.2
D5 Standard, D6 Professional
BeitragVerfasst: Sa 06.09.03 23:54 
Also für die erste Frage hätt ich auch noch`n Code:

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:
procedure SaveStringGrid(StringGrid: TStringGrid; const FileName: TFileName); 
var 
  f:    TextFile; 
  i, k: Integer; 
begin 
  AssignFile(f, FileName); 
  Rewrite(f); 
  with StringGrid do 
  begin 
    // Write number of Columns/Rows 
    Writeln(f, ColCount); 
    Writeln(f, RowCount); 
    // loop through cells 
    for i := 0 to ColCount - 1 do 
      for k := 0 to RowCount - 1 do 
        Writeln(F, Cells[i, k]); 
  end; 
  CloseFile(F); 
end; 

// Load a TStringGrid from a file 

procedure LoadStringGrid(StringGrid: TStringGrid; const FileName: TFileName); 
var 
  f:          TextFile; 
  iTmp, i, k: Integer; 
  strTemp:    String; 
begin 
  AssignFile(f, FileName); 
  Reset(f); 
  with StringGrid do 
  begin 
    // Get number of columns 
    Readln(f, iTmp); 
    ColCount := iTmp; 
    // Get number of rows 
    Readln(f, iTmp); 
    RowCount := iTmp; 
    // loop through cells & fill in values 
    for i := 0 to ColCount - 1 do 
      for k := 0 to RowCount - 1 do 
      begin 
        Readln(f, strTemp); 
        Cells[i, k] := strTemp; 
      end; 
  end; 
  CloseFile(f); 
end; 

// Save StringGrid1 to 'd:\temp.txt': 

procedure TForm1.Button1Click(Sender: TObject); 
begin 
  SaveStringGrid(StringGrid1, 'd:\temp.txt'); 
end; 

// Load StringGrid1 from 'd:\temp.txt': 

procedure TForm1.Button2Click(Sender: TObject); 
begin 
  LoadStringGrid(StringGrid1, 'd:\temp.txt'); 
end;


Und auch für die zweite:

ausblenden 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:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; 
  Rect: TRect; State: TGridDrawState); 
var 
  dx: Integer; 
begin 
  with (Sender as TStringGrid) do 
  begin 
    // Don't change color for first Column, first row 
    if (ACol = 0) or (ARow = 0) then 
      Canvas.Brush.Color := clBtnFace 
    else 
    begin 
      case ACol of 
        1: Canvas.Font.Color := clBlack; 
        2: Canvas.Font.Color := clBlue; 
      end; 
      // Draw the Band 
      if ARow mod 2 = 0 then 
        Canvas.Brush.Color := $00E1FFF9 
      else 
        Canvas.Brush.Color := $00FFEBDF; 
      Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top + 2, cells[acol, arow]); 
      Canvas.FrameRect(Rect); 
    end; 
  end; 
end;


Bei solchen Fragen ist www.swissdelphicenter.ch oft die erste Wahl.

_________________
...To err is human, but to really foul things up requires a computer.
Hochhäusl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 57



BeitragVerfasst: So 07.09.03 09:59 
Danke für eure Antworten!

Ich bin jetzt viel weiter, jedoch kann ich noch immer nicht die Farbe einer einzelen Zelle ändern. Gibt es da auch was wie ACol/ ARow?
Habe nichts in der "Suche" gefunden!

:D
grayfox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 800

win98, winXP
D4 Standard; D6 Personal
BeitragVerfasst: So 07.09.03 15:15 
hallo hochhäusl!

hast dir den 2. teil des codes angesehen?
ausblenden Delphi-Quelltext
1:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;					

dort hast du dein aRow & aCol, das du suchst

mfg, stefan
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 08.09.03 14:43 
@Hochhäusl: Bitte erstelle in Zukunft für jede Frage ein eingenes Topic mit einem ausagekräftigen Titel in der richtigen Sparte :!:

Gruß
Tino