Search code examples
c#winformsdata-bindingado.netbindingsource

Reassign textbox.text on bindingsource currentitem change event


I am just learning bindingsources etc. I have added my textbox databindings like so:

txtTitle.DataBindings.Add("Text", bindingNavigator1.BindingSource.Current, "Title");

When the user clicks the next button on the navigator do I have to handle the bindingsource currentitem changed event to say

txtTitle.Text = ((MyObject)bindingsource.CurrentItem).Title??

I would have thought this would be automatic as I have a lot of controls so seems tedious


Solution

  • You should bind to the bindingsource itself as in:

    txtTitle.DataBindings.Add("Text", bindingNavigator1.BindingSource, "Title");
    

    Then you don't need to handle any further events. As you say, that would be tedious.