For the example to work take the following steps:
- Drop a TMSFNCDataGrid onto a Form
- Change the name to
DataGrid
- Write
Joined
into the name-property of the second column (Joined)
Constructor with the following code:
__fastcall TForm67::TForm67(TComponent* Owner)
: TForm(Owner)
{
this->DataGrid->MoveColumn(2, 0);
}
//---------------------------------------------------------------------------
In the DataGridCellLayout-Event the following code:
void __fastcall TForm67::DataGridGetCellLayout(TObject *Sender, TTMSFNCDataGridCell *ACell)
{
auto pColumn = this->DataGrid->Columns->Items[ACell->Column];
if (pColumn->Name == L"Joined")
{
ACell->Layout->Fill->Color = clRed;
}
}
//---------------------------------------------------------------------------
Expected behavior: The Joined
column has red background. Actual behavior: the Name
column has red Background:
I ended up with this "workaround" which does what i want to achieve:
auto pColumn = this->DataGrid->Columns->Items[ACell->Column];
if (pColumn->Name == L"Joined")
{
int nIndex{this->DataGrid->Root->RealToDisplayColumn(pColumn->Index)};
this->DataGrid->Layouts[nIndex][ACell->Row]->Fill->Color = clRed;
}
But in my opinion ACell->Layout should format tha right cell?