BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

stringgrid

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
Matt
Guest





PostPosted: Tue Jun 28, 2005 7:33 am    Post subject: stringgrid Reply with quote



Hello,

Is there a stringgrid where you can set the font color and background color
for each cell seperately?
(I don't use the F1Book component because builder 5 does not have help for
this component and it's probably to complex for what I want).

Thanks.


Back to top
JD
Guest





PostPosted: Tue Jun 28, 2005 9:46 am    Post subject: Re: stringgrid Reply with quote




"Matt" <marthijn (AT) vuelta (DOT) tmfweb.nl> wrote:
Quote:

Is there a stringgrid where you can set the font color and
background color for each cell seperately?

Use TStringGrid.

Quote:
I don't use the F1Book component because builder 5 does not
have help for this component

I doubt that. In any case:

http://www.tamaracka.com/search.htm

is an archive that will have sample code for almost every
situation you might encounter.

Quote:
and it's probably to complex for what I want

Actually it's quite simple. To accomplish what you want, set
the TStringGrid's DefaultDrawing property false to tell the
object that you will be responsible for drawing the cells and
then add an OnDrawCell event to the object. The following
sample performs the default drawing:

void __fastcall TForm1::StringGrid1GridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect, TGridDrawState State)
{
TStringGrid *pGrid = static_cast<TStringGrid*>( Sender );
TCanvas *pCanvas = pGrid->Canvas;

if( State.Contains(gdFixed) ) // if a fixed col or row cell
{
pCanvas->Brush->Color = pGrid->FixedColor;
pCanvas->Font->Color = pGrid->Font->Color;
}
else
{
if( State.Contains(gdSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;
}
else
{
pCanvas->Brush->Color = pGrid->Color;
pCanvas->Font->Color = pGrid->Font->Color;
}
}

pCanvas->FillRect( Rect );
::DrawText( pCanvas->Handle, pText.c_str(), -1, &Rect, DT_LEFT | DT_SINGLELINE | DT_VCENTER );

if( State.Contains(gdFocused) && pGrid->Options.Contains(goDraw­FocusSelected) )
{
pCanvas->DrawFocusRect( Rect );
}

}
//-------------------------------------------------------------

Please direct your attention to the above if/else block:

if( State.Contains(gdSelected) )
{
pCanvas->Brush->Color = clHighlight;
pCanvas->Font->Color = clHighlightText;
}
else
{
pCanvas->Brush->Color = pGrid->Color;
pCanvas->Font->Color = pGrid->Font->Color;
}

The else block is where you would change the colors for the
individual cell. You could just modify that else block to test
the ACol and ARow parameters but if you want something more
than setting a particular column or row to a particular color
I would suggest using the grid's Objects property to hold a
value that denotes what color to use for the cell.

The Objects property is just like the Cells property in that
for each cell, there is an Objects and they are referenced
using the same indexing method: pGrid->Objects[ Col ][ Row ].
How they differ is that the Objects property is of type TObject
which is 32bits.

Since TColor is also 32bits, you'd need to use a code where
the HIWORD and LOWORD represent the 2 desired colors.

~ JD


Back to top
Tom Woodrow
Guest





PostPosted: Tue Jun 28, 2005 10:06 pm    Post subject: Re: stringgrid Reply with quote



Second that!

Tom Woodrow
www.dacworks.com


Pete Fraser wrote:
Quote:
www.tmssoftware.com - advstringgrid is excellent
Cheers, Pete

"Matt" <marthijn (AT) vuelta (DOT) tmfweb.nl> wrote in message
news:42c0fcff (AT) newsgroups (DOT) borland.com...

Hello,

Is there a stringgrid where you can set the font color and background
color for each cell seperately?
(I don't use the F1Book component because builder 5 does not have help for
this component and it's probably to complex for what I want).




Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.