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.
Unfortunately, activation email could not send to your email. Please try again.

GridControl Fastest Way to Set TextColor To Red if Value < 0

Thread ID:

Created:

Updated:

Platform:

Replies:

28915 May 12,2005 09:19 AM May 13,2005 07:17 AM Windows Forms 1
loading
Tags: GridControl
Jason Hales
Asked On May 12, 2005 09:19 AM

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) { base.OnQueryCellInfo(e); try { // 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; } } } } catch{} } Help would be very much appreciated Thanks Jason

Administrator [Syncfusion]
Replied On May 13, 2005 07: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.
double d;
string text = grid[row,col].Text;
if(double.TryParse(text, System.Globalization.NumberStyles.Any, null, out d))
{
     //d will have the double value
}
 

CONFIRMATION

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.

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.

;