Live Chat Icon For mobile
Live Chat Icon

I get a ‘This would cause two bindings in the collection to bind to the same property’ error message. What might cause this

Platform: WinForms| Category: Data Binding

As the message suggests, the code is calling Control.DataBindings.Add twice with what amounts to the same parameters.

One way this might happen is if you call the same code more than once in your program to reload your datasource for some reason, and in this code, you have lines such as:

Me.TextBox1.DataBindings.Add('Text', myDataTable, 'Col1Name')
Me.TextBox2.DataBindings.Add('Text', myDataTable, 'Col2Name')
Me.TextBox3.DataBindings.Add('Text', myDataTable, 'Col3Name')

On the second call, this would attempt to add a duplicate binding to the DataBindings collection. One solution is to Clear the DataBindings collection before you add your new binding.

Me.TextBox1.DataBindings.Clear();
Me.TextBox1.DataBindings.Add('Text', myDataTable, 'Col1Name')
Me.TextBox2.DataBindings.Clear();
Me.TextBox2.DataBindings.Add('Text', myDataTable, 'Col2Name')
Me.TextBox3.DataBindings.Clear();
Me.TextBox3.DataBindings.Add('Text', myDataTable, 'Col3Name')

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.