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
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
I have implemented InititalizeRow for the moment, it will iterate over the cells and set any <0 decimal columns to Red.
I am using the object data source (IBindingList<T>). The error message I get from the designer (Property) is...
---------------------------
Microsoft Visual Studio
The DataType cannot be set for bound columns.
OK