I'm currently trying to bind an array element from a class to a text box without success.
class Test{
...
string[] toto = new string[]{"element1"};
}
Test test;
void form_load()
{
test = new Test();
textBox1.DataBinding.Add("Text", test, "toto(0)");
}
(I tried as discussed here : Winforms Databinding to element in array)
But I get :
System.ArgumentException: 'Cannot bind to the property or column Requires(0) on the DataSource. Parameter name: dataMember'
If I bind it like this:
checkBox2.DataBindings.Add(new Binding("Checked", config.Requires[0], ""));
It works but I can't implement INotifyPropertyChanged for updating the form on change perform by the code.
Does anyone have any idea?
Edit: After binding, the form should be updated when the element of the array is updated.
Quite possibly there is a better way to do this, but what you could do is create an instance of
BindingSource
for each element in the array, set theBindingSource.Position
property, then set that as the binding for theTextBox
.Edit: Made the Data Binding 2-way... changing the value in the control updates the object, changing the value from the object changes the control.