Click here to Skip to main content
16,022,669 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to I test e.FormattedValue.ToString against IsDBNull or IsNothing? I tried

VB
If Not IsNothing(e.FormattedValue.ToString) Then Exit Sub

dgvPhysCME.Rows(e.RowIndex).ErrorText = "Field must not be empty"
e.Cancel = True


and

VB
If Not IsDBNull(e.FormattedValue.ToString) Then Exit Sub


When I blank out the cell it always takes the "Exit Sub" path.

Thanks, Eddie
Posted
Updated 5-Feb-11 11:48am
v5

Try using the String.IsNullOrEmpty method.
MSDN Documentation.
It is likely that your FormattedValue equals string.Empty. An empty string is still a value so IsNothing won't work and IsDBNull won't work because the string value won't equal System.DBNull.Value.
 
Share this answer
 
Comments
Eddie Niebruegge 5-Feb-11 20:03pm    
Thanks... that worked. Eddie
Sergey Alexandrovich Kryukov 5-Feb-11 23:08pm    
Of course that should have worked. A 5.
--SA
Espen Harlinn 6-Feb-11 7:32am    
Good answer :)
I am not sure that the FormattedValue can be Nothing, since it is the value to be displayed, which for a blanked cell would probably be String.Empty. The same applies to DBNull only more so, if you see what I mean.

If you want to test for DBNull then I would suggest using e.Value.

Otherwise add
VB
AndAlso Not String.IsNullOrEmpty(e.FormattedValue.ToString) Then Exit Sub
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Feb-11 23:09pm    
Sure. A 5.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900