Changing cell color

I saw a previous question about how to set the color of an individual cell in a TStringGrid, and the
solution was to use the GridDrawCell event to do it manually.  However I need some help figuring out
how to do that exactly...  I have tried:

Form2->Grid->Canvas->Brush->Color = clRed;
Form2->Grid->Canvas->TextOutA(Rect.left, Rect.top, "Test");

This results in black text with a red background, however I just want the
foreground to stay the same and change the text color only.  I have also
tried:

Form2->Grid->Canvas->Pen->Color = clRed;
....TextOut...

But this has no effect, I just get black text.
0
Jeffrey
8/28/2009 12:32:31 AM
embarcadero.cppbuilder.using 1848 articles. 1 followers. Follow

5 Replies
437 Views

Similar Articles

[PageSpeed] 8

<Jeffrey McKay> wrote in message news:155447@forums.codegear.com...
>I saw a previous question about how to set the color of an individual cell 
>in a TStringGrid, and the
> solution was to use the GridDrawCell event to do it manually.  However I 
> need some help figuring out
> how to do that exactly...  I have tried:
>
> Form2->Grid->Canvas->Brush->Color = clRed;
> Form2->Grid->Canvas->TextOutA(Rect.left, Rect.top, "Test");
>
> This results in black text with a red background, however I just want the
> foreground to stay the same and change the text color only.  I have also
> tried:
>
> Form2->Grid->Canvas->Pen->Color = clRed;
> ...TextOut...
>
> But this has no effect, I just get black text.

Form2->Grid->Font->Color = clRed;
0
Utf
8/28/2009 5:50:48 AM
>> 
> Form2->Grid->Font->Color = clRed;


Thanks, but I'm not quite there yet.  My GridDrawCell code is below.  In the example I am trying to set all the
strings in column 1 to clBlue.  What happens is, everything is still black, and I get a continuous flicker.  I get the
idea that the event handler is being called continuously for every cell, even if it has not been changed, and the
flicker is caused be switching between blue and black.  I tried setting the Grid property DefaultDrawing to false,
which gets rid of the flicker, but column 1 still does not change to blue.  Any suggestions?

void __fastcall TForm2::GridDrawCell(TObject *Sender, int ACol, int ARow, TRect &Rect,
		  TGridDrawState State)
{
String S;

   S = Form2->Grid->Cells[ACol][ARow];
   if (ACol == 1 && ARow > 0)
	  Form2->Grid->Font->Color = clBlue;
   else
	  Form2->Grid->Font->Color = clBlack;

   Form2->Grid->Canvas->TextOutA(Rect.left+2, Rect.top+2, S);

}
0
Jeffrey
8/28/2009 6:52:34 AM
Il Thu, 27 Aug 2009 23:52:34 -0700, Jeffrey McKay <> ha scritto:

>Thanks, but I'm not quite there yet.  My GridDrawCell code is below.  In the example I am trying to set all the

You should use 

  Form2->Grid->Canvas->Font->Color = anycolor;

instead of

  Form2->Grid->Font->Color = anycolor;

However, in these cases, maybe it's better to use directly 
(switch to) a TDrawGrid and peek the data straight from 
a more "convenient" container than the Strings property 
of TStringGrid. 

Get rid of that unuseful StringGrid. :-)

Regards

Giuliano
0
Giuliano
8/28/2009 7:11:03 AM
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol, int 
ARow, TRect &Rect,
          TGridDrawState State)
{
  if( State.Contains(gdSelected)&&State.Contains(gdFocused) ){
    StringGrid1->Canvas->Brush->Color = clGreen;
    StringGrid1->Canvas->FillRect( Rect );
    StringGrid1->Canvas->Font->Color = clYellow;
    StringGrid1->Canvas->TextOut(Rect.Left,Rect.Top,StringGrid1->Cells[ACol][ARow]);
    return;
  }
  if( State.Contains(gdSelected) ){
    StringGrid1->Canvas->Brush->Color = clBlue;
    StringGrid1->Canvas->FillRect( Rect );
    StringGrid1->Canvas->Font->Color = clRed;
    StringGrid1->Canvas->TextOut(Rect.Left,Rect.Top,StringGrid1->Cells[ACol][ARow]);
    return;
  }
  if( State.Contains(gdFocused) ){
    StringGrid1->Canvas->Brush->Color = clRed;
    StringGrid1->Canvas->FillRect( Rect );
    StringGrid1->Canvas->Font->Color = clBlue;
    StringGrid1->Canvas->TextOut(Rect.Left,Rect.Top,StringGrid1->Cells[ACol][ARow]);
    return;
  }
  if( State.Contains(gdFixed) ){
    StringGrid1->Canvas->Brush->Color = StringGrid1->FixedColor;
    StringGrid1->Canvas->FillRect( Rect );
    StringGrid1->Canvas->Font->Color = StringGrid1->Font->Color;
    StringGrid1->Canvas->TextOut(Rect.Left,Rect.Top,StringGrid1->Cells[ACol][ARow]);
    return;
  }
  StringGrid1->Canvas->Brush->Color = StringGrid1->Color;
  StringGrid1->Canvas->FillRect( Rect );
  StringGrid1->Canvas->Font->Color = StringGrid1->Font->Color;
  StringGrid1->Canvas->TextOut(Rect.Left,Rect.Top,StringGrid1->Cells[ACol][ARow]);
}
0
Utf
8/28/2009 2:19:49 PM
<Jeffrey McKay> wrote in message news:155447@forums.codegear.com...

> I just want the foreground to stay the same and change the
> text color only.

Set the Canvas->Brush->Color to the value of the Grid->Color (unless the 
cell is selected, in which case use clHighlight instead), and then change 
Canvas->Font->Color to the desired text color.

-- 
Remy Lebeau (TeamB)
0
Remy
8/28/2009 6:07:55 PM
Reply:

Similar Artilces:

Change cell color in a cell when hyperlink is clicked
I have a table across the bottom of my form, when a user clicks a hyperlink in one of the cells, I want the bgcolor of the cell to change. You can use the onClick event of the cell to change its bgcolor property. For example:<td bgcolor="black" onclick"bgcolor='white';">This is a test!</td>This uses event propogation to capture the click event which is passed down from the link. Steven BeyRecursion: see Recursion Don't know what I'm doing wrong, I used your example and it it doesn't want to cooperate. The bgcolor automatically deafults to the oncli...

How to change the highlighted color of the selected item using user defined color instead of window system color
Thx, JJ You'd have to create your own "selection" system... you can use a rectangle object and change its visibility as needed to simulate a highlighted row, but you'd have to have (and use) your own versions of SelectRow() and its kin. "JJ" <jasonyklau@sinaman.com> wrote in message news:41205c89@forums-1-dub... > Thx, > JJ > > Why do your own selectRow()? If I'm not wrong, coding this is the visible property should work: "if(getRow()=selectedRow(),1,0)" hth, JMR > You'd have to create your own...

Change Datagrid cell color based on cell value
I was wondering if there is a way to change the background color of an individual cell in a datagrid based on it's value. (I code in VB) Example: I have a Due Date field and the cells need to be highlighted yellow for all dates that are over 30 days old. Then for all of the dates that are over 60 days old, their cell backgrounds would need to be red. Thanks for the help in advance Dan Take a look @ Change Color of a Column Based on Column Values In your case you can use <Table> tag and change the <td> background color using helper function HTH Sushila ...

change grid cells back color (Cells Blinks)
Dear devs my case is im building a website similar to stocks websites, i used ajax for refreshing issues and gridview for disiplaying data. now the data will change frequently and i want to color the changed data (coloring the cells of changed data). but the problem is i dont know which cell is changed and which one staied remain. thanks for helpingJaffar N. Khalid Hi:   From your description my understanding is that you're using UpdatePanel and a Timer. Is it right? If my understanding is correct you can get the original data before GridView is bound again. Store it in a globa...

Changing a Cells color based on another cells value
We want to change the color of a previous cell based on the value in the current cell. For example, say we are ranking items as they are read into the datagrid. We have several columns of data we want to rank for first and second place. Once we encounter a value that is greater than the previous high value we would like to change the previous high values cell color to yellow and the new high cells color to green. For example column 1 in the following table would have 12 highlighted in green and 10 highlighted in yellow. See the following table. Column 2 would have 11 highlighted green and th...

Changing cell colors in a datagrid based on the information contained in the cell
Any help I can get would be greatly appreciated. I have a datagrid with information in several columns that show the status of certain aspects of a given project. Red for an area in trouble in trouble, yellow for those having problems that could become serious and green for those running as planned. What I would like to do is have the cell color change to correspond to the status of the project. Since the project managers update the status of projects as needed the color would need to change based on the text entered into the cell turning either red, yellow or green to correspond. H...

how do I conditionally change bkg color of datalist cell and make the content of the cell clickable
Hi all, 1) how do I change background color of a datalist cell based on an attribute value (of a xml file) and make the content of the cell clickable ? 2) assuming the datalist is in an iframe. How do I make the cell content value available to another iframe page via clickable/url passing technique?  Thanks Here's how to change the color (BALANCE_COL is the cell index): protected void GridViewFun_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.DataIt...

Change Color of a cell
I hav one question please.. I want to color a particular cell in a datagrid dynamically..how this can be done?? Regards,Punithkumar http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q  Hi,In RowDataBound event of GridView, you can do that.like this,  protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)    {        if (e.Row.RowType == DataControlRowType.DataRow)        {            e.Row.Cel...

changing color of a cell
hi i have a hypelink within a tablecell. when i click the hyperlink i'd like to change te cell's backcolor. how can do it? i tried ..... <asp:tablecell id=cell1> <asp:hyperlink onclick="cell1.backcolor=green" navigateurl=page.aspx> ..... it doesnt work. can u tell me? thanks a lot   document.getElementById("someId").style..... but not sure you are adding it to that control the correct way.... EricPascarello.com | Twitter epascarello | LinkedIn hi   thanks <script language="javscript"> function ChangeCellColor(CellElement) {  CellElement...

Change color of a cell
How would I change the color of a cell from code. I can alter a table: ContentTable.BackColor = Color.Blue ,but I cannot figure out how to alter a cell. Any help would be welcome. Hi, I provided some sample code here: view post 834064. Grz, Kris.Read my blog. Handy Firefox plugins for web developers.Workaround for non working Mark as answer buttons....

Changing data grid cell colors based on information contained within the cells #2
I posted the following question the other day and aspdotnetv2 kindly responded with some code. However this seemed to require the use of the repeater control to accomplish my goal. It worked as it should. But if I do this I loose the functionally of the "data grid" that I wanted. Does anyone know a way to accomplish this using the data grid instead of the repeater?? I have a data grid with information in several columns that show the status of certain aspects of a given project. Red for an area in trouble in trouble, yellow for those having problems that could become serious ...

How to change tree view's (web control) back color, font color and font size using CSS (Cascading Style Shteets)
Hi All, I have created tree view (web control) but i want to change all the properties of it, through single style sheet. Like all other controls (label, text box and combo box) it's not possible to change all the properties of treeview through single style sheet by including it to the contol ???? Please help........ MAITRAY. Sorry. No external css. but these attributes: DefaultStyle="background:#CCCCCC;border:solid 1px;color:black;font-size:8pt" HoverStyle="color:blue;font-name:Arial" SelectedStyle="c...

Changing color of a cell in a gridview
hello, If i have a gridview and i have following columns in it : FirstName, LastNname, Due Amount,  due date. 1)I want to check and change the color to red of that Cell in the Due Amount Column if the due Amount is more then 20 dollars, 2) change the color of a a Column Cell , DueDate  date if it is past due 30 days.   Thanks Amir        learning.. : ) You could put some logic in in the databinding logic:  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowE...

Changing cell background color
    Hello, Im trying to make a navigation menu thing kind of like the one at the top of the asp.net page. Where the background color of the cell changes to a different color when your mouse goes over it and changes to another color when its clicked.Does any one know of any good tutorials etc on how to do this? (im quite new btw :P)Thanks!Sorry if that doesnt make sence and have posted in the wrong area :(( Hi Anthony,   If you're looking for same navigation bar as like as ASP.NET, check it out from CommunityServer Source. it is basically opensource - so you can use/sha...

Web resources about - Changing cell color - embarcadero.cppbuilder.using

Changing room - Wikipedia, the free encyclopedia
A changing room , locker room , dressing room (usually in a sports, theater or staff context) or changeroom (regional use) is a room or area ...

Beyond Timeline: The Changing Face Of Facebook Ads
Despite the hype, timeline may not be the most exciting, or important change coming on March 30. Expanded advertising opportunities may unlock ...

Robert Scoble - Micromedia, how it's changing what we blog - Facebook
Jeremiah Owyang wrote an interesting piece about micromedia and how it's changing what we do on blogs and how we distribute media (er, ideas, ...

8 Ways the Changing Facebook Home Page Will Affect Application Virality
For developers who live and die by the changes Facebook makes to the way information flows through the service, every little Facebook tweak has ...

Changing Lanes (@chginglanes) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Changing the way business decisions are made
We believe that social data has unlimited value, and near limitless application. Today, we’re taking an important step toward unleashing this ...

The Right and Wrong Reasons for Changing Jobs
... your profile is a clue to the folks at LinkedIn that you’re thinking of switching jobs, so don’t be The Right and Wrong Reasons for Changing ...

We're Changing Our Name (Back) to Stack Overflow
We are Stack Overflow. You may know us from such popular websites as Stack Overflow Q&A, Stack Overflow Careers, The Stack Exchange Q&A Network, ...

The Tao of Twitter: Changing your life and business 140 characters at a time - Amazon
It's time to take the mystery out of Twitter. Twitter may be the most powerful business and personal networking platform ever created but it ...

App Store - Voices 2 ~ fun voice changing!
Read reviews, get customer ratings, see screenshots, and learn more about Voices 2 ~ fun voice changing! on the App Store. Download Voices 2 ...

Resources last updated: 12/2/2015 7:24:37 PM