aehimself 396 Posted December 4, 2019 Hello, In Delphi 10.3.3 I have a DBGrid component with the following handler: procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); Var r: TRect; begin If ZQuery1.RecNo Mod 2 = 0 Then Begin r := Rect; InflateRect(r, -1, -1); DBGrid1.Canvas.Lock; Try DBGrid1.Canvas.Pen.Color := clRed; DBGrid1.Canvas.Pen.Width := 2; DBGrid1.Canvas.MoveTo(r.Left, r.Top); DBGrid1.Canvas.LineTo(r.Right, r.Top); FInally DBGrid1.Canvas.Unlock; End; End; end; Everything works fine: Until the moment when I enable VCL Styles. At first, it appears okay: But if you start to click (especially try to drag and drop column headers) things start to fall apart: This does not seem to happen when there are no Styles enabled. Anyone has an idea on what is this and how to fix it? Thanks! Share this post Link to post
Lars Fosdal 1792 Posted December 5, 2019 Have you tried without the lock/unlock? You are after all already inside a grid on draw event. A possible workaround could be to do an invalidate on the grid after a drag/drop. Also - how a mod 2 = 0 can draw every three rows, is a bit of a mystery 😉 Share this post Link to post
aehimself 396 Posted December 5, 2019 Yes, original code was without .Lock and .Unlock but since it started to glitch out I decided to include it (and it remained). As for the Mod 2 it is no mystery, only my mistake: took the shots before changing the value - was experimenting with a lot of things before asking. Invalidating after a column drag will not be the solution - as this is only the sample code, and this is how I could recreate the issue. In the original project some lines are drawn correctly, some are in black (no matter that the color is set to red), some does not appear at all even without dragging involved. Share this post Link to post
Lars Fosdal 1792 Posted December 5, 2019 8 17 minutes ago, aehimself said: Yes, original code was without .Lock and .Unlock but since it started to glitch out I decided to include it (and it remained). As for the Mod 2 it is no mystery, only my mistake: took the shots before changing the value - was experimenting with a lot of things before asking. Invalidating after a column drag will not be the solution - as this is only the sample code, and this is how I could recreate the issue. In the original project some lines are drawn correctly, some are in black (no matter that the color is set to red), some does not appear at all even without dragging involved. What if you call Inherited before drawing the rect? I see that in some of my code I only do my custom drawing if State = []. Share this post Link to post
aehimself 396 Posted December 5, 2019 Soooo... the bad thing is that without major changes the original project started to work correctly and I don't know why!!! Especially since the raw DBGrid seems to have this issue and I don't remember fixing anything in my descendant... Share this post Link to post