[Solved] dbgrid ondrawcolumncell bug ? lazarus / 39-Graphics ---------------------------------------------------------------------- amigoface · 2012-05-22 15:12 hi, this is my first lazarus project, i come from delphi like most of you i guess and i have this little wierd dbgrid drawin problem here is my ondrawcolumncell method Code: [Select]procedure TProduitsFrame.DBGrid1DrawColumnCell(Sender: TObject;   const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var    s:string;    DTParams: DrawTextParams;    r : Trect; begin r := rect; with DTParams do begin   cbSize := SizeOf(DrawTextParams);   iTabLength := 6;   iLeftMargin := 10;   iRightMargin := 10; end; with TDBGrid(Sender).canvas do begin  brush.style:=bssolid; font.assign(column.Font); if gdSelected in state then  begin    brush.Color:= _DBGrid_ROW_SELECTED;    font.color:=Clwhite;  end  else  begin    font.color:= Column.Font.color;    if TDBGrid(Sender).dataSource.DataSet.RecNo mod 2 = 0 then       Brush.Color := clwhite    ELse       Brush.Color := _DBGrid_ROW_ALTERNATE;    end; fillrect(rect); brush.style:=bsclear; s := column.Field.DisplayText; if Column.Field.Index = 4 then begin   case column.Field.AsInteger of      2 : dm.GridIcons.Draw(TDBGrid(Sender).canvas, rect.Left, rect.Top,0, true);      1 : dm.GridIcons.Draw(TDBGrid(Sender).canvas, rect.Left, rect.Top,1, true);   end; end else begin If s<> '' then case column.Alignment of   tacenter:  DrawTextEx(Handle, PChar(S), -1,     R, DT_CENTER + DT_VCENTER + DT_SINGLELINE  + DT_END_ELLIPSIS,     @DTParams);   taleftjustify:  DrawTextEx(Handle, PChar(S), -1,     R, DT_LEFT + DT_VCENTER + DT_SINGLELINE + DT_END_ELLIPSIS,     @DTParams);   tarightjustify:  DrawTextEx(Handle, PChar(S), -1,     R, DT_RIGHT + DT_VCENTER + DT_SINGLELINE + DT_END_ELLIPSIS,     @DTParams); end; end; end; end;  every thing is ok the first time a fire the app but if i switch to another window and go back again i have some wierd effects 1st image everything ok (http://data.imagup.com/10/1152364933.png) 2nd image not everything ok (http://data.imagup.com/12/1152364886.png) btw my lazarus version is : 0.9.30.02 date 2011-11-04 révision SVN : 33306 i386-win32/win64 any helkp is welcome thanks and good day ---------------------------------------------------------------------- ludob · 2012-05-22 16:46 The area where no rows are displayed is not re-painted correctly. So apparently nothing wrong with the ondrawcolumncell because that is only called for fixed and non fixed rows.  Can you post the settings of DBGrid1? You can copy the relevant part of the lfm. Can you also try and set DBGrid1.color to clGreen and check if the area without rows is painted in that color. ---------------------------------------------------------------------- amigoface · 2012-05-22 17:51 here the fbgrid settings Code: [Select]  object DBGrid1: TDBGrid[0]     Left = 0     Height = 312     Top = 80     Width = 966     Align = alClient     AutoFillColumns = True     BorderStyle = bsNone     Color = clGreen     Columns = <          item         Title.Caption = 'Produit'         Width = 237         FieldName = 'PRD_NOM'       end          item         Title.Caption = 'Qte en stock'         Width = 237         FieldName = 'PRD_QTE'       end          item         Title.Caption = 'Seuil'         Width = 237         FieldName = 'PRD_SEUIL'       end          item         Title.Caption = 'Alerte'         Width = 238         FieldName = 'PRD_ALERTE_ICON'       end>     DataSource = Datasource1     DefaultDrawing = False     DefaultRowHeight = 38     FixedCols = 0     Flat = True     Options = [dgColumnResize, dgTabs, dgRowSelect, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgAutoSizeColumns]     Scrollbars = ssVertical     TabOrder = 0     OnDrawColumnCell = DBGrid1DrawColumnCell   end i have tried your clgreen suggestion with the same issue, also i have tried to paint the entire dbgrid area before cell painting with this code Code: [Select]cr := TDBGrid(Sender).ClientRect; Brush.Style:= bssolid; Brush.Color:= clwhite;  TDBGrid(Sender).canvas.FillRect(cr); and same problem thanks for your assistance ---------------------------------------------------------------------- ludob · 2012-05-22 18:19 Tried your settings and your ondrawcolumncell  (except for the dm.GridIcons.Draw) and used clLime and clBlue for the color constants. Can't reproduce on winXP with lazarus 1.1. Image attached. When you say Quotei have tried your clgreen suggestion with the same issue,does this mean that the area is never filled with green or that it is once but not repainted when invalidated? Does the area fill green in the IDE? Perhaps worth grabbing one of the lazarus 1.1 snapshots on http://freepascal.dfmk.hu/test/lazarus/ ---------------------------------------------------------------------- amigoface · 2012-05-22 18:43 what happens if you resize your window or put another window on top ? btw i will try a newer lazarus version and see what happens ---------------------------------------------------------------------- amigoface · 2012-05-23 04:02 following your suggestion, i have upgraded my lazarus version to a newer one : Lazarus-1.1-37386-fpc-2.6.1-20120522-win32.exe and now evrything work wonderfull as possible thanks a lot ludob really appreciate !