Hola aguml.
Acabo de probar el codigo que publicaste y me funciona bién, lo que si veo es que me quedó un detalle de la prueba, cambiar la siguiente línea,
Código:
HDC dc = StringGrid1->Canvas->Handle;
pero eso hace más reusable la rutina, no es solución al comportamiento que mencionas. No sé que puede estar pasando aunque supongo que se debe a una cuestión de superposición de colores ...
Te pongo el código completo de mi prueba (que funciona correctamente) para que puedas controlar
con el tuyo.
Código:
/* darle algunos valores a la grilla */
void __fastcall TForm1::FormCreate(TObject *Sender)
{
StringGrid1->Options << TGridOption(goEditing);
for (register int c = 0; c < StringGrid1->ColCount; c++)
for (register int r = 0; r < StringGrid1->RowCount; r++)
StringGrid1->Cells[c][r] = IntToStr(c+r);
}
/* organizar la presentación */
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TStringGrid *SG = static_cast<TStringGrid*>((TStringGrid*)(Sender));
String cad = SG->Cells[ACol][ARow];
HDC dc = SG->Canvas->Handle; // <<<< --- Cambio
register int Flags = (ACol == 1 ? DT_CENTER | DT_VCENTER | DT_SINGLELINE :
DT_RIGHT | DT_VCENTER | DT_SINGLELINE);
cad += (ACol > 1 ? " " : "");
if (State.Contains(gdFixed)) {
SG->Canvas->Brush->Color = clBtnFace;
SG->Canvas->Font->Color = clWindowText;
SG->Canvas->FillRect(Rect);
DrawText(dc, cad.c_str(), cad.Length(), &Rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
else if(State.Contains(gdSelected)) {
SG->Canvas->Brush->Color = clAqua;
SG->Canvas->Font->Color = clWindowText;
SG->Canvas->FillRect(Rect);
DrawText(dc, cad.c_str(), cad.Length(), &Rect, Flags);
}
else {
if (ARow % 2 == 0){
SG->Canvas->Brush->Color = clSilver;
SG->Canvas->Font->Color = clWindowText;
}
else {
SG->Canvas->Brush->Color = SG->Color;
SG->Canvas->Font->Color = SG->Font->Color;
}
SG->Canvas->FillRect(Rect);
DrawText(dc, cad.c_str(), cad.Length(), &Rect, Flags);
}
}
Si tenes alguna dificultad, no dudes en avisame y te adjunto los fuentes.
Saludos