Question : Unable to tab out of empty textbox on a bound control

I have many Windows forms with bound Text boxes.  It doesn't matter whether the underlying database column is nullable or not, but all numeric type columns (Int, money or decimal) are giving me problems.  

If the field is null it will be blank on the form, if it is not null it will show the database value. If I enter the field I can change it or leave it alone and tab out - no problems.  However, If I remove the value and try to tab out it won't let me.  It just stays on that field until I enter something.  

This is most noticeable when the underlying column is nullable, but it is not restricted to nullable!  It displays blank which is what I want, but if I enter something in this field and then decide to remove it and move off that field it just stays there!

I have specific validation on the fields but I have debugged every combination and unless I raise an error I NEVER exit with e,Cancel = true !

It's not my code that's preventing the field having a blank after having a non blank entry.

Any help would be gratefully appreciated.

Answer : Unable to tab out of empty textbox on a bound control


I guess this could be related to converting empty values to numbers. Generally, when converting empty string to numbers (using double.Parse or Convert.ToDouble methods), it will throw error. Your situation may be related to this...internally some error happens and moving out is cancelled..

I dont know how you do the data binding...See if you can use Binding.Parse event to take control of the conversion. sample here => http://msdn.microsoft.com/en-us/library/system.windows.forms.binding.parse.aspx

(Binding class is used in textBox1.DataBindings.Add method)

See if you can use Binding.DataSourceNullValue and Binding.NullValue properties in your code, to handle the null cases..(http://msdn.microsoft.com/en-us/library/system.windows.forms.binding_members.aspx)
Random Solutions  
 
programming4us programming4us