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. Image for the cookie policy date

Changing cells text color

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

8 Replies

AD Administrator Syncfusion Team July 21, 2004 11:02 AM

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


KM kevin musters July 29, 2004 11:11 AM

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,


AD Administrator Syncfusion Team July 29, 2004 11:17 AM

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.


KM kevin musters July 29, 2004 11:22 AM

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?


AD Administrator Syncfusion Team July 29, 2004 11:54 AM

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?


KM kevin musters July 29, 2004 12:03 PM

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,


AD Administrator Syncfusion Team July 29, 2004 12:17 PM

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.


KM kevin musters July 29, 2004 01:00 PM

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

Loader.
Live Chat Icon For mobile
Up arrow icon