Hello,
I have a grid wiht a column where the Style = Integer. The property on the DataOsurce is int too, so everything should work fine.
At runtime, the grid displays the default value of zero. Then I edit it and set it to blank. When I tab out I get an error thrown by the grid "Object of type 'System.DBNull' cannot be converted to type 'System.Int32". I guess empty text is interpreted as DBNull.Value, which can not be converted to an Int32. I tried setting Nullable = Disallow, with no success.
Is there a way to not allow entering blank (null) values on a numeric column?
As a side note, I think the Nullable property should provide an option "TypeDefault". When selected, blank text should be converted to defaullt(T), where T is the data type of the column.
One more thing: I like the new design of the forums, but there is no forum-specific search (or I haven't found it?), only global. On a global search, only one page of results are displayed, there's no links to fetch more results.
DataFilter is a good idea and clean way as Mike suggested. The following is a KnowledgeBase article on how to implement a DataFilter:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=5014
Magued
Mike, Magued:
Thanks for the answer. A DataFilter can solve the problem, but I just found a simpler way. Setting the Column.Nullable property to Nothing does the trick.
I tried with int, double and DateTime. When tabbing out of a blank cell the value seems to revert back to default(T), where T is the data type of the column.
This is not very intuitive, and the documentation doesn't say anything about value types:
I think it is more clear if there's a new value in the Nullable enum "TypeDefault", that returns the default(T) when the cell is blank.