Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi Grafik in DBGrid (https://www.delphipraxis.net/134343-grafik-dbgrid.html)

bwolf 20. Mai 2009 11:14


Grafik in DBGrid
 
Hi Leute,

ich möchte in einem DBGrid in einer Zelle statt des Textes eine Grafik anzeigen.
Mit diesem Code von delphi.about.com wird schonmal eine Grafik zusätzlich vor dem Text angezeigt:

Delphi-Quellcode:
  // dbgridDrawColumnCell
  if (Column.Field.FieldName = 'name') then
  begin
    bitmap := TBitmap.Create;
    try
      //grab the image from the ImageList
      ImageList1.GetBitmap(0,bitmap);
      //Fix the bitmap dimensions
      bmpWidth := (Rect.Bottom - Rect.Top);
      fixRect.Right := Rect.Left + bmpWidth;
      //draw the bitmap
      dbgrid.Canvas.StretchDraw(fixRect,bitmap);
    finally
      bitmap.Free;
    end;
      // reset the output rectangle,
      fixRect := Rect;
      // add space for the graphics
      fixRect.Left := fixRect.Left + bmpWidth;
  end;
Ich probiere nun seit geraumer Zeit den Text zu entfernen, schaffs aber nicht so wirklich.
Kann mir da einer auf die Sprünge helfen?

Danke euch!

Andreas Schilling 20. Mai 2009 11:52

Re: Grafik in DBGrid
 
Warum hast du der DBGridspalte überhaupt ein Datenfeld zugewiesen wenn der Inhalt nicht angezeigt werden soll sondern das Bild?
Ohne DB-Feld
Delphi-Quellcode:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if datacol = 5 then begin
    ...
  end;
end;

bwolf 20. Mai 2009 12:17

Re: Grafik in DBGrid
 
Hi Andreas,

weil ich entsprechend dem Inhalt des Feldes das eine oder das andere Bild anzeigen will.

Andreas Schilling 20. Mai 2009 12:33

Re: Grafik in DBGrid
 
Den Inhalt des Feldes kannst du doch direkt in der Datenquelle abfragen.

bwolf 20. Mai 2009 12:45

Re: Grafik in DBGrid
 
Womit du auch Recht hast :oops:
Werde es mal Probieren, danke dir.


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:11 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz