Search code examples
delphidelphi-xetstringgrid

Odd drawing issue (black cells) in TStringGrid


I encountered something really really really odd with TStringGrid (Delphi XE). I have seen that sometimes when I click the first line in my grid, it turns black (or shows scrambled canvas 'stolen' from other controls on form). It happens ONLY in certain configurations, when the grid receives focus. Once you click another area in the grid everything looks ok until the focus is moved to another TStringGrid.

How to reproduce:

  • put TWO string grids on a form
  • set them as shown below (Update: I realized that goRowSelect and goEditing must be 'true')
  • click the first cell in one grid -> nothing happens
  • click the first cell in the second grid -> the first cell gets black (see screenshot)

The problem appears also in other circumstances (not necessary to have 2 grids on a form), but I managed to reproduce it only when I have 2 grids.

object grid1: TStringGrid <------- same for Grid2
  Left = 2
  Top = 8
  Width = 422
  Height = 381
  BevelEdges = [beLeft, beTop]
  DefaultColWidth = 80
  DefaultRowHeight = 15
  DoubleBuffered = True
  FixedCols = 0
  Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goDrawFocusSelected, goColSizing, goEditing, goRowSelect, goFixedHotTrack]
  ParentDoubleBuffered = False
  TabOrder = 1
end

Any idea on how to fix this?

enter image description here


Solution

  • I can reproduce your problem with XE3 as well. After I have reset ParentDoubleBuffered to True, the problem is gone.

    Generally speaking, when I see odd black rectangle in a control, I will first check the ParentDoubleBuffered settings. I saw you have enabled double buffering for the two grids. Do you have any special reason to do that? If you intend to avoid flickering during resizing or cell update, there are some techniques helpful.