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

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

Thread ID:





28915 May 12,2005 01:19 PM UTC May 13,2005 11:17 AM UTC WinForms 1
Tags: GridControl
Jason Hales
Asked On May 12, 2005 01:19 PM UTC

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 11:17 AM UTC

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


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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