Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
865
Condition formatting on Bound columns
posted

Here is my situation:

public class MyClass {

 [DisplayName("My Column")]

public decimal MyField { get; set; }

}

A collection (that implements IBindingList) of these classes are bound to a Grid. The grid has a manually created schema that defines MyField, and defines a condition format that should set the foreground red when the value is negative.

The problem is that the data type of the column in the designer defaults to String, and doesn't let me change it because it's a bound column. Subsequently it looks like the conditional formatting is trying to do a less than operation using strings, therefore comparing "-10" to "0", instead of -10 to 0.

The result of this is that the conditional formatting is never applied to negative values.  If I change the conditional format to "Starts With", "-", which works, but this won't help me when I want to do things like comparing whether a decimal value is less than 5 (or any other arbitrary decimal value).

What am I doing wrong here? How can I do "real" conditional formatting based on the underlying data type of the property on the class, rather than the String data type that the manually created schema assumes?

Regards,

Mark

 

 

Parents
No Data
Reply
  • 37774
    posted

    Mark,

    It doesn't seem like this is an issue with ConditionFormatting, but rather with how the grid is getting the structure of your grid through the BindingManager.  Something is definitely wrong if the grid is picking up that a decimal column has a DataType of 'string', but it's difficult to say why this might be happening without seeing it in action; could you post a small sample so that I could look into it?  Are you using an ObjectDataSource to bind the grid to a list of these objects?  If you're manually defining the schema, you should be able to change the DataType of the column yourself.

    A workaround is to handle your appearance resolution in the InitializeRow event, but of course this removes the design-time support of conditional formatting that you're trying to do.

    -Matt

Children