Results 1 to 2 of 2

Thread: Validating a databound control

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2013
    Location
    San Francisco, CA
    Posts
    487

    Validating a databound control

    I have a form that only has one control - a textbox (txtAccount) - and it is bound to a BindingSource with the binding's DataSourceUpdateMode property set to OnValidation.

    I've added a button (btnSave) to the form's BindingNavigator that saves (persists) changes to the underlying SQLite database.

    The form has an event handler for the ColumnChanged event of the underlying bound DataTable that enables the btnSave button.

    In this scenario, since there is only a single control on the form, after the user has entered data in the txtAccount textbox, the user has to click the BindingNavigator.PositionItem (textbox control) to trigger the txtAccount.Validating event (because the form has no other control to select (tab/click).

    Is there a better (more intuitive) way to do this without having the user click the PositionItem control?

    I've thought about using the txtAccount.KeyPress event and a timer to detect when the user stops typing and then explicitly call the txtAccount.Validating event but would like to get the opinion of others before going that route.
    Last edited by Mark@SF; Dec 6th, 2021 at 05:54 AM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Validating a databound control

    You'd need to change the update mode to OnPropertyChanged. The alternative would be to handle the TextChanged event of the control and handle the enabling of the Button there, separate to any other validation. That may render separate validation pointless.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width