![]() |
DBGrid Icon aus ImageList
Hallo,
versuche aus einer Imagelist ein Bitmap zu laden.
Delphi-Quellcode:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState); var i : Integer; Wert: string; bmpImage: tBitmap; intX, intY: Integer; begin if (DBGrid1.DataSource.DataSet.RecordCount = 0) then Exit; if column.FieldName = 'ICON' then with DBGrid1.Canvas do begin fillRect(rect); bmpImage := tBitmap.Create; try Wert := DBGrid1.DataSource.DataSet.FieldByName('GRID').Value; if Wert = '0' then begin DBGrid1.Canvas.Brush.Color := clwhite; DBGrid1.Canvas.Font.Color := clHighlight; end else if Wert = '1' then begin //DBGrid1.Canvas.Brush.Color := clred; //DBGrid1.Canvas.Font.Color := clyellow; ImageList1.Draw(DBGrid1.Canvas,Rect.Left+(Column.Width-17),Rect.Top+1,0); // Was ist hier falsch? end else |
AW: DBGrid Icon aus ImageList
Hier die Lösung! :-D
Delphi-Quellcode:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState); var bitmap : TBitmap; fixRect : TRect; bmpWidth : integer; imgIndex : integer; Wert : String; begin fixRect := Rect; if Column.Field = DBGrid1.DataSource.DataSet.FieldByName('ICON')then begin Wert := DBGrid1.DataSource.DataSet.FieldByName('GRID').Value; if Wert = '1' then begin ImgIndex := 0; end else if Wert = '0' then begin ImgIndex := 1 end; bitmap := TBitmap.Create; try ImageList1.GetBitmap(imgIndex,bitmap); bmpWidth := (Rect.Bottom - Rect.Top); fixRect.Right := Rect.Left + bmpWidth; DBGrid1.Canvas.StretchDraw(fixRect,bitmap); finally bitmap.Free; end; fixRect := Rect; fixRect.Left := fixRect.Left + bmpWidth; end; DBGrid1.DefaultDrawColumnCell(fixRect,DataCol,Column,State); end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:29 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-2025 by Thomas Breitkreuz