Autor Beitrag
delphimike
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 117



BeitragVerfasst: Mo 11.07.05 15:12 
Hallo

ich möchte in einem DBGrid Daten aus der Datenbank etwas umformatiert darstellen.
Dazu dient die Methode DrawColumnCell
Wie komme ich aber an die Datanbankdaten des anzuzeigenden Feldes dran?
Kann ich diese verändert übder die Automatik darstellen oder muß ich zwangsweise über Canvas gehen

Gruß Mike

_________________
kaum macht man was richtig, schon gehts!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 11.07.05 15:39 
Schau dir auf meiner HP den Source zur Komponente Feld-Formatierer an.
Der kann alle gängigen Formatierungen, die auch mit dem Feld-Editor definierbar sind, durchführen.
delphimike Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 117



BeitragVerfasst: Mo 11.07.05 16:03 
danke, es geht hier nicht um irgendwelche Standardformate, sondern ich muß z.b. in den Strings Teile ausblenden.. Mit dem Programm konnte ich leider gar nichts anfangen

mein bisheriger Code:

die Funktion Textrect gibt nichts aus!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TAufList.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if not (gdselected in state) then
  if Odd(DBGrid1.DataSource.DataSet.RecNo) then DBGrid1.Canvas.Brush.Color:=ZebraCol1
                                           else DBGrid1.Canvas.Brush.Color:=ZebraCol2;

  if Column.fieldname='Datum' then
  begin
    ... wie komme ich an den Feldinhalt ...
    ... Format anpassen ...
    DBGrid1.Canvas.Textrect (Rect,1,1,'Feldinhalt');
  end
  else DBGrid1.defaultdrawcolumncell (Rect,DataCol,Column,State);
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.

_________________
kaum macht man was richtig, schon gehts!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 11.07.05 17:40 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TAufList.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
  s : String;
begin
  if not (gdselected in state) then
  if Odd(DBGrid1.DataSource.DataSet.RecNo) then DBGrid1.Canvas.Brush.Color:=ZebraCol1
                                           else DBGrid1.Canvas.Brush.Color:=ZebraCol2;

  if Column.fieldname='Datum' then
  begin
//    ... wie komme ich an den Feldinhalt ...
// z.B. so:
    s := DBGrid1.DataSource.DataSet.Fields[DataCol].AsString;
    ... Format anpassen ...
    DBGrid1.Canvas.Textrect (Rect,1,1,'Feldinhalt');
  end
  else DBGrid1.defaultdrawcolumncell (Rect,DataCol,Column,State);
end;
delphimike Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 117



BeitragVerfasst: Di 12.07.05 08:07 
das klingt gut, danke, nur bleibt noch das Problem, daß Textrect nichts ausgibt, das Feld ist leer ?????

_________________
kaum macht man was richtig, schon gehts!