This is a migrated thread and some comments may be shown as answers.

Validating blank numeric cells

2 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ESA
Top achievements
Rank 1
ESA asked on 27 Aug 2011, 01:13 AM
Hello,
I have a grid bound to a DataTable where some numeric cells come in as blank, as the data behind is dbnull. This is a perfectly valid condition, as those cell do not require the user to enter a number.
However, after I click on those cells I enter edit mode, and while in edit mode I am required to enter a number, otherwise it doesn't let me leave the edit mode. I can alway press ESC to leave the edit mode, but then it leaves the old value in the cell. The side effect of this behaviour is that it doesn't let me change a cell that already has a number into a blank (dbnull), which should be perfectly legal in our case.
When trying to validate the blank numeric cell the output window is showing an error message from the system exception saying the dbnull value cannot be converted to a nullable Single.
Is there any switch, any grid property or any flag that allows to validate blank numeric cells and convert them to dbnull?
Thank you

2 Answers, 1 is accepted

Sort by
0
ESA
Top achievements
Rank 1
answered on 29 Aug 2011, 06:09 PM
Any answers to that, please?
0
Nedyalko Nikolov
Telerik team
answered on 02 Sep 2011, 07:55 AM
Hi Tracey,

Sorry for the late answer.

Unfortunately .NET framework cannot convert string.Empty to null, therefore you are getting such validation warning. However you could easily meet your goal with a few lines of code. Just create IValueConverter and apply it to the Column.DataMemberBinding. I'm attaching a sample project that demonstrates this approach. You will Northwind database on a SQLEXPRESS server (but of course you could change the connection string within MainWindow.xaml.cs).

Let me know if this doesn't help.

Greetings,
Nedyalko Nikolov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
ESA
Top achievements
Rank 1
Answers by
ESA
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Share this question
or