Hi, I have a user control that derives from GridControl. I''m overridding OnQueryCellInfo in order to set a cell''s TextColor to red if the cell''s value is less than 0
But this now runs very very slowly. Is there a preferred/faster way to achieve this? Here''s my current code:
protected override void OnQueryCellInfo(GridQueryCellInfoEventArgs e)
// For some reason E.Style.CellValue is null!!!
if (e.Style.CellType != "Header")
string cellValue = (string)base[e.RowIndex, e.ColIndex].CellValue;
if (cellValue != null && cellValue.Length > 0)
double parsedValue = Double.Parse(cellValue);
if (parsedValue < 0)
e.Style.TextColor = Color.Red;
Help would be very much appreciated
ADAdministrator Syncfusion Team May 13, 2005 06:17 AM
Using QueryCellInfo is the proper place, but always calling Double.Parse(cellValue) and trying to catch an exception when it fails is not the quickest way to handle this. Instead use double.TryParse. This will test for a valid value without raising an exception and not raising an exception is generally significantly quicker than rasing one.
string text = grid[row,col].Text;
if(double.TryParse(text, System.Globalization.NumberStyles.Any, null, out d))
//d will have the double value