Autor Beitrag
alexbrodi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23


Delphi und BCB 2006
BeitragVerfasst: Mi 15.11.06 10:27 
Hallo,

in einem StringGrid bereite ich Daten aus einer Datenbank auf. Mit Überschrift Summen usw.

Wenn ich das StringGrid aktualisiere habe ich das Problem das in Zellen in denen vor der Aktualisierung etwas gestanden ist und danach leer sind, der alte Text drin stehen bleibt.

Wie zeichnet man das Grid komplett neu.

Gruß

Alex
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 15.11.06 10:43 
Moin!

Probier das mal so: StringGrid1.Invalidate;

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
alexbrodi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23


Delphi und BCB 2006
BeitragVerfasst: Mi 15.11.06 14:58 
Hallo Narses,

tut leider nicht.

Gruß

Alex
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: Mi 15.11.06 16:16 
Hallo
wie trägst Du denn die Daten ins Grid ein? Und was verstehst Du unter Aktualisieren des Grids?

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
alexbrodi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23


Delphi und BCB 2006
BeitragVerfasst: Mi 15.11.06 16:37 
Hallo,

Die Daten werden aus der DB per Button Click abgerufen und im Stringrid dargestellt. Beim nächsten Button click werden die Daten erneut abgerufen und dargestellt. In den Zellen, wo neue Daten hineingeschrieben werden werden die alten überschrieben. In die Zellen wo keine neuen Daten eingetragen werden(leere Zellen), dort werden die alten Daten angezeigt und werden nicht überschrieben.

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:
92:
93:
procedure TForm1.Button1Click(Sender: TObject);
var
...

begin
//  emptyRows := TStringList.Create;
  DM1.IBDatabase1.DatabaseName := ComboBoxServer.Text + ':' + ComboBoxPfad.Text;
  DM1.IBDatabase1.Connected := true;
  DM1.IBQueryLKW1.SQL.Text :='....';
  DM1.IBQueryLKW1.Open;
  //StringGrid1
  with DM1.IBQueryLKW1 do begin
    FetchAll;
    StringGrid1.RowCount := RecordCount+1;
    First;
    ze := 0; ........
 
    while not Eof do begin;
      baustellenNr := FieldByName('BAUNR').AsString;
      sortenNr := FieldByName('SORNR').AsString;
      // 1. Schleife, es wird erste Baustelle in der Tabelle eingetragen
      // Neue Baustelle
      if (baustellenNr<>lastBNR) then begin
        //Letzte Summe drucken
        if lastBNR<>'' then begin
          StringGrid1.Cells[sp+3,ze] := 'Summe:';
          StringGrid1.Cells[sp+4,ze] := FloatToStr(summe)+' to';
          Inc(ze);
        end;
        if ze>ze_max then
          ze_max := ze;
        ze := ze_max;
        //Inc(ze);
        //folge Baustellen werden in die Zeilen nach unten eingetragen
        StringGrid1.Cells[0,ze] := FieldByName('BAUNAME1').AsString;
        lastBNR := baustellenNr;
        Inc(ze);
        sp := -6;
        lastSNR := '';
        ze_start := ze;
        ze_max := 0;
      end;
      //Neue Sorte
      if (sortenNr<>lastSNR) then begin
        //Summe drucken
        if (lastSNR<>'') then begin
          StringGrid1.Cells[sp+3,ze] := 'Summe:';
          StringGrid1.Cells[sp+4,ze] := FloatToStr(summe)+' to';
          Inc(ze);
        end;

        if ze>ze_max then
        ze_max := ze;
        ze := ze_start;
        Inc(sp,6);
        StringGrid1.Cells[sp,ze] := FieldByName('SORNR').AsString;
        StringGrid1.Cells[sp+1,ze] := FieldByName('SORNA1').AsString;
        lastSNR := sortenNr;
        Inc(ze);
        isumme := 0;
        if sp+6>sp_max then
          sp_max := sp + 6;
       end;
      StringGrid1.Cells[sp,ze] := FieldByName('LSNR').AsString;
      StringGrid1.Cells[sp+1,ze] := TimeToStr(FieldByName('DATUMBELEG').AsDateTime);
      StringGrid1.Cells[sp+2,ze] := FieldByName('FAHRZEUG').AsString;
      StringGrid1.Cells[sp+3,ze] := FieldByName('FAHRER').AsString;
      StringGrid1.Cells[sp+4,ze] := FieldByName('BERNETTO_IN_T').AsString;
      isumme := isumme + Round(FieldByName('BERNETTO_IN_T').AsFloat * 1000);
      summe := isumme / 1000;
      lastBNR := baustellenNr;
      lastSNR := sortenNr;
      Inc(ze);
      if ze>ze_max then
         ze_max := ze;
      Next();
    end;
    if sp<0 then begin
      sp := 0;
      StringGrid1.Cells[sp,ze] := '';
      MessageDlg('Es sind keine Daten vorhanden!',mtInformation,[mbOK],0);
    end;
    StringGrid1.Cells[sp+3,ze] := 'Summe:';
    StringGrid1.Cells[sp+4,ze] := FloatToStr(summe)+' to';
    Inc(ze);
    if ze>ze_max then
       ze_max := ze;
    //letztes Ergebnis der letzten Zeile
    StringGrid1.RowCount := ze_max + 1;
    StringGrid1.ColCount := sp_max;
  end;
  DM1.IBQueryLKW1.Close;
  end;


Gruß

Alex

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
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: Mi 15.11.06 20:35 
was ich an deinem code nicht verstehe:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
       sp := -6;  
      ...
        //Summe drucken  
        if (lastSNR<>'') then begin  
          StringGrid1.Cells[sp+3,ze] := 'Summe:';

sp auf -6 setzen und dann +3 ? ist immer noch negativ und außerhalb des gültigen Zellenbereichs, da muß Du doch schon eine AV sehen?

ausblenden Delphi-Quelltext
1:
2:
    //letztes Ergebnis der letzten Zeile  
    StringGrid1.ColCount := sp_max;

Du setzt die Anzahl der Spalten erst am Ende? Bist Du dir sicher, daß das funktionieren kann?

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
alexbrodi Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23


Delphi und BCB 2006
BeitragVerfasst: Do 16.11.06 00:08 
Hallo,

der Quellcode mit sp := -6 .. muß so sein da die Schleifen unterschiedlich durchlaufen werden: Ich habe lang gebraucht bis das mit der formatierung gepasst hat.

Wie das ganze aussieht. (siehe Bild)

Gruß

Alex
Einloggen, um Attachments anzusehen!
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Do 16.11.06 00:17 
In dem gescannten sieht man, dass man tatsächlich was sieht. :mrgreen: Aber es geht doch hier drum :

user profile iconalexbrodi hat folgendes geschrieben:
..Wie zeichnet man das Grid komplett neu...


Du musst die einzelnen Zellen durchgehen und diese auf '' setzen. Also mit RowCount und ColCount.

_________________
Gruß
Hansa