We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Changing cells text color

Thread ID:





16660 Jul 21,2004 02:59 PM UTC Jul 29,2004 05:00 PM UTC WinForms 8
Tags: GridControl
Gil Kalo
Asked On July 21, 2004 02:59 PM UTC

Hi, I''m trying to change a cells text color,for example: Somewhere in any method I''m making the following call: gridDataBoundGrid.GetViewStyleInfo(1,1).TextColor = Color.Red The call is made, but nothing happened?! Any ideas? Thanks in advance, Gil

Administrator [Syncfusion]
Replied On July 21, 2004 03:02 PM UTC

Here is a KB article that discusses this. http://www.syncfusion.com/Support/article.aspx?id=560

kevin musters
Replied On July 29, 2004 03:11 PM UTC

Yes, using the PrepareViewStyleInfo works, but I find it is being called much too often. I would like to cut back on processor usage. Can I set the style within my CellClick event? (databoundgrid). Thanks,

Administrator [Syncfusion]
Replied On July 29, 2004 03:17 PM UTC

No. You cannot set a individual cell style property (other than CellValue) in a GridDataBoundGrid. Unless you are doing some heavy calculating to decide the color, PrepareviewStyleInfo is usually very quick. If you are doing heavy calculating to find the color, you might do that in CellClick (or some other event), anc cache this value somewhere (simple variable or hashtable or ??), and then just retrieve it in PrepareViewStyleInfo. The point is that the grid will have to get the color from somewhere every time the cell is needed to be drawn, and getting it from PrepareViewStyleInfo can be reasonably efficient as long as you can get the color you want quickly.

kevin musters
Replied On July 29, 2004 03:22 PM UTC

I am only checking the first column inside the datatable. (1st column checkbox, 2nd text) If it is true, I color the row background blue, if it is false, I color the row background. There are no heavy calculations going on, I find if I am performing a selection of over 250-300 records there is a significant pause of about 2-3 seconds. Any ideas?

Administrator [Syncfusion]
Replied On July 29, 2004 03:54 PM UTC

Can you post your PrepareViewStyleInfo code? First comment is that this should only be hit for visible cells. Do you have a monitor that display 250-300 rows?

kevin musters
Replied On July 29, 2004 04:03 PM UTC

Here is the code inside PrepareViewStyleInfo string sState = this.gdbgList[e.RowIndex, 1].Text.ToLower(); if (sState.Equals("true")) { e.Style.BackColor = Color.PowderBlue; } else { e.Style.BackColor = Color.White; } The purpose of this code is to change any row that has the first column value of "true" to have a background color of blue. So is this changing the colors for only the visible fields? Or does this change all of the fields? If it changes only the visible fields, then my performance lag is coming from somewhere else. Thanks for your help,

Administrator [Syncfusion]
Replied On July 29, 2004 04:17 PM UTC

PrepareViewStyleInfo should only be fired when the cell is being drawn which means the cells have to be visible. You can see this by adding a Console.WriteLine(e.Colindex.ToString() + " " + e.RowIndex.ToString()); in your PrepareViewStyleInfo. Then your output window will show exactly which cells are being drawn. (This will slow things done...). Regarding you code, you might want to change string sState = this.gdbgList[e.RowIndex, 1].Text.ToLower(); to string sState = (e.ColIndex != 1) ? this.gdbgList[e.RowIndex, 1].Text.ToLower() : e.Style.Text.ToLower(); I do not think it should take that 2-3 seconds you mentioned. I suspect something else is going on? Are you outputing a lot of debug output, for instance. This can slow things down.

kevin musters
Replied On July 29, 2004 05:00 PM UTC

Clay, yes I am doing a lot of debug output in my console. Thanks for all your help, I''ll devise a solution from here. Musters


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon