In a nutshell, this databinding works correctly
tbTotalTaxDue.DataBindings.Add("Text", I, "TotalTaxDue");
Namely, when I enter an invalid value—like an empty string—then tab out of the TB, the value therein just reverts to the previous value. This makes sense since the value开发者_Python百科 entered won't go into the object property of type decimal. Unfortunately though, either of these databindings:
tbTotalTaxDue.DataBindings.Add("Text", I, "TotalTaxDue", true, DataSourceUpdateMode.OnPropertyChanged, 0, "C");
tbTotalTaxDue.DataBindings.Add("Text", I, "TotalTaxDue", true, DataSourceUpdateMode.OnValidation, 0, "C");
Behave differently in that when the user enters an empty string, the input will not let the user tab out of the Text Box. Is there any way to get the databinding to display as a currency, but simply cancel any invalid edits?
You have a couple options:
- Subclass - TextBoxand override the- OnValidatingevent. If- Textis empty, exit before calling- MyBase.OnValidating()to suppress the event.
- Set - CausesValidation = Falseon the- TextBox, and handle the- TextChangedevent. If- Textis not empty, manually validate it.
I hope this helps.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论