DBGrid и цвет фона заголовка
22.05.2026
Как изменить цвет фона для заголовка в DBGrid

Why Column->Title->Color fails

In modern Windows, the TDBGrid uses the operating system's "Themes" to draw headers. When themes are active, Windows takes over the painting of the button-like headers, ignoring the Color property entirely.

To fix this specifically for the Title:

  1. Set DBGrid1->DrawingStyle = gdsClassic , not gdsThemed
  2. Try setting DBGrid1->FixedColor = clBtnFace; (this affects all headers).
  3. If you need individual colors per header, you must use the OnDrawTitleCell event and manually paint the background using DBGrid1->Canvas->FillRect(Rect).
void __fastcall TForm1::DBGrid1DrawColumnCell(TObject *Sender, const TRect &Rect,
		  int DataCol, TColumn *Column, TGridDrawState State)
{
/*	if (DBGrid1->Columns->Items[DataCol]->FieldName == "Host")
	{
//		int size = wcslen(DBGrid1->Columns->Items[DataCol]->FieldName.c_str()+1);
		DBGrid1->Columns->Items[DataCol]->Width = 100;

 //		DBGrid1->Columns->Items[DataCol]->Title->Font->Color = (TColor)clBlue;
		DBGrid1->Columns->Items[DataCol]->Title->Color = (TColor)clGreen;//clBtnFace;
	}
  */
	if ( DataCol < 2 )
	{
		DBGrid1->Columns->Items[DataCol]->Title->Font->Color = (TColor)clBlue;
   		DBGrid1->Columns->Items[DataCol]->Title->Color = (TColor)clGreen;
//		DBGrid1->Columns->Items[DataCol]->Width = 100;
	}


}