1

Here's the simplest of scenarios. I have a Form with a few TextBoxes and a BindingSource, bound to a DataSet instance, and the TextBoxes bound to the BindingSource. Entering text in these TextBoxes doesn't raise CurrentItemChanged event on my BindingSource; not even when I change focus to another textbox. It only fires when I move to another record, which is what one would expect from CurrentChanged. According to MSDN:

The CurrentItemChanged event is raised in response to all of the circumstances that raise the CurrentChanged event. Additionally, CurrentItemChanged is also fired whenever the value of one of the properties of Current is changed.

Please note that I don't want to call EndEdit() because that would commit my changes.

EDIT

Here's my binding code. Now I have added OnPropertyChanged too, without any luck.

Me.bsCatItems.DataMember = "catalog_items"
Me.bsCatItems.DataSource = Me.DsInventory
Me.bsItems.DataSource = Me.bsCatItems
Me.bsItems.DataMember = "FK_CatalogItems_Items"
Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("Text", Me.bsItems, "consignment_count", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged))
dotNET
  • 31,005
  • 20
  • 138
  • 226

3 Answers3

0

I'm not sure how this works in winforms but in wpf you can set the updatesourcetrigger of the binding to property-changed. If this is set, every time you type something into the textbox, the propertychanged-event will be fired.

I am pretty sure that there's an equal mechanism in winforms.

Tomtom
  • 8,699
  • 7
  • 48
  • 87
0

You are looking for DataSourceUpdateMode.OnPropertyChanged When you bindind control on a form, the default is OnValidation.

You must change it to OnPropertyChanged for it to update every time a user types a value into a control

this.MyTextbox.DataBindings.Add(new Binding("Text", this.bindingSource, "fieldName", true, DataSourceUpdateMode.OnPropertyChanged));

You can also do it from the designer (if you use VisualStudio)

Jens Kloster
  • 10,727
  • 5
  • 37
  • 53
  • For a second I thought this really was the answer. My happiness didn't last long. – dotNET Mar 06 '13 at 07:09
  • hmmm I could have sworn this was the anwser. try posting the code, there you set the `BindingSource.DataSource` and where the bindingsource is beeing used to bind to a control – Jens Kloster Mar 06 '13 at 07:16
  • Hi, Did you find a solution for this.. DataSourceUpdateMode.OnPropertyChanged).. What events do I handle for any edits made to a text box. – user575219 Oct 25 '13 at 03:56
0

You must implement the INotifyPropertyChanged interface to enable the CurrentItemChanged event to be raised - the binding source will automatically subscribe to the PropertyChanged event.

To see an example of how the INotifyPropertyChanged can be implemented see for example this link

Community
  • 1
  • 1
Zrethreal
  • 191
  • 1
  • 14