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
AD
Administrator
Syncfusion Team
July 21, 2004 03:02 PM UTC
Here is a KB article that discusses this.
http://www.syncfusion.com/Support/article.aspx?id=560
KM
kevin musters
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,
AD
Administrator
Syncfusion Team
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.
KM
kevin musters
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?
AD
Administrator
Syncfusion Team
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?
KM
kevin musters
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,
AD
Administrator
Syncfusion Team
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.
KM
kevin musters
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