Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Background color of TStringGrid cell when selected 1

Status
Not open for further replies.

bhobbs

Programmer
Jul 11, 2005
3
0
0
US
Hi all,

I am trying to customize the drawing of the cells of a TStringGrid. I need certain cells that contain hex values to have a different background color. I have written the method below which is called for the OnDrawCell event.

It works fine except when the cell is selected. In this case, the background reverts back to the default white color instead of the hex color.

Does anyone know how I can fix this problem?

void UT_CustomStringGridDrawCell(TStringGrid *StringGrid,
int Col,
int Row,
TRect &Rect,
TGridDrawState State,
bool ValidCell,
bool HexCell)
{
AnsiString Text;

if ( State.Contains(gdFixed) )
{
//Fixed row.
StringGrid->Canvas->Brush->Color =
clBtnFace;
StringGrid->Canvas->Font->Color =
ValidCell ? clWindowText :
RDCFG_INVALID_COLOR;
StringGrid->Canvas->FillRect(Rect);
Frame3D(StringGrid->Canvas,
Rect,
clBtnHighlight,
clBtnShadow,
1);
}
else if (HexCell)
{
//Hex Input Cell
StringGrid->Canvas->Brush->Color =
RDCFG_HEX_COLOR;
if (State.Contains(gdSelected))
{
StringGrid->Canvas->Font->Color =
ValidCell ? clHighlightText :
RDCFG_INVALID_COLOR;
}
else
{
StringGrid->Canvas->Font->Color =
ValidCell ?
StringGrid->Font->Color :
RDCFG_INVALID_COLOR;
}
StringGrid->Canvas->FillRect(Rect);
}
else if (State.Contains(gdSelected))
{
//Selected cell.
StringGrid->Canvas->Brush->Color =
clHighlight;
StringGrid->Canvas->Font->Color =
ValidCell ? clHighlightText :
RDCFG_INVALID_COLOR;
StringGrid->Canvas->FillRect(Rect);
}
else
{
//Normal.
StringGrid->Canvas->Brush->Color =
StringGrid->Color;
StringGrid->Canvas->Font->Color =
ValidCell ? StringGrid->Font->Color :
RDCFG_INVALID_COLOR;
StringGrid->Canvas->FillRect(Rect);
}

Text = StringGrid->Cells[Col][Row];
StringGrid->Canvas->TextRect(Rect,
Rect.Left,
Rect.Top,
Text);
}

 
Yes, I did that and it had no effect. It does the same thing regardless of whether DefaultDrawing is set to true or false.
 
the cell color does return to the proper color
when the cell is not selected , correct.

tomcruz.net
 
I would think the default Highlight activity
responding to the selected cell should be altered.

we can change this property in the display properties
in the control panel, but how do we manipulate the
selected color of an object in code.

is there an api somewhere that we use to interface with
the selected window color.

tomcruz.net
 
InplaceEditor

I did not know it was there. I looked for it in help
and found a whole new world underneath the top layer I
have been working in.

you have just complicated my life so much.

thanks ;-)

TC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top