DataBox-related data: unable to exit

I have a text field associated with an object property (actually multiple text fields) in the form. This is for the editor for the object. When I edit some objects and change values ​​in one of the text fields, I cannot leave the text field (neither by the tab, nor by clicking on another text field). However, this is not always the case - when editing other objects (of the same type), it works fine.

Here's the snipet code:

txtValue.DataBindings.Add("Text", _SourceObject, "PlannedValue", True, DataSourceUpdateMode.OnPropertyChanged, Nothing, "c") txtEstPlacements.DataBindings.Add("Text", _SourceObject, "EstimatedPlacementCount") txtReference.DataBindings.Add("Text", _SourceObject, "Reference") 

Any suggestions?

+4
source share
3 answers

Sounds like a data validation issue. Verify that the CausesValidation properties in the form controls are set to true or false.

Also check the AutoValidate property on the form. It is probably set to EnablePreventFocusChange (which is the default).

It may also be that the value provided in the text field cannot be converted to the type of property to which it is bound to the source data object. I believe the Convert class is used for this (although maybe I'm wrong).

You might want to check out this article on MSDN, which details the validation check.

+11
source

If your form has AutoValidate == EnablePreventFocusChange, then you will get focus stuck in any field that fails validation.

Note that the check is considered unsuccessful if there is an exception when writing the value to the object.

Try setting a breakpoint at the entry point of the property installer associated with the control where the cursor is stuck. Then one step to find out if an exception is thrown.

If the breakpoint never fires, an exception can occur within the framework of the Databinding.

Contrary to popular belief, the data binding structure performs log errors and other useful information - this uses the System.Diagnostics namespace support. I forget the details, but they are on MSDN - you should be able to view the diagnostics in the Visual Studio message box during the launch of your application. Very useful for troubleshooting Databinding.

+5
source

To fix a validation error that is related to the inability to bind data to the DBNull.Value set in textbox.text, you can add the following line in the Form_Load section:

 TextBox1.DataBindings["Text"].NullValue = string.Empty; 

for each text field that you want empty values ​​to be validated correctly.

Learn more about Microsoft Connect .

and on:

Unable to escape empty text field

+3
source

All Articles