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.
What is the DataSource of your grid? Are you sure the data source itself supports null? Null is not a valid value for an Int. If you use a DataTable or UltraDataSource, then these handle nulls for you. But if you are using a custom data source with a property of type Int, then nothing the grid does will ever allow it to set an int to Null.
oscarmorasu said: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.
There's currently no forum-specific search, but I think they are working on adding it back in ASAP. :)
Magued:
Thanks for the sample code. I should have sent a sample code myself. On your example you bind the grid to a DataTable. In my case I bind the grid to a BindingSource. Then I set the BindingSource.DataSource to a List<Customer>, where Customer is a business object.
I'm attaching your original sample, modified to be closer to my scenario. I still get the error when setting the column to blank. One more thing, we are using version 8.2.20082.1000.
Mike:
I'm using a BindingSource, then I bind a collection of busniess obejcts to the grid. On the business object the property is of type int, so nulls or DBNulls are not allowed. I guess there's something going on in the BindingSource that interprets a blank value as a DBNull.