Hi,
I am making a custom control based on a Panel. The main idea is to bind a datatable to this panel. There are functions for selecting a row + updating, saving and deleting this row in the custom Panel. The only problem is binding the data. I have this function:
private void _addBindings()
{
_src = new BindingSource();
_src.DataSource = datarow;
foreach (Control c in this.Controls)
{
string type = c.GetType().ToString();
if (type.IndexOf("TextBox") > -1)
{
//Tried: _src
//Tried: datarow
c.DataBindings.Clear();
c.DataBindings.Add(new Binding("Text", datarow.Table, c.Name));
}
}
}
As you can see, I want to bind to _src or datarow tot the TextBoxes. But all the bindings fail with the exception: ArgumentException - Cannot bind to the property or column on the DataSource. I see that the columns of a datarow are numbered and not named. So I also tried to put the columnnumber instead of c.Name.
The only Binding that works is with the datatable. The problem is that it always uses the first row, even if the 3th row is selected. (The values of the 3th row are actually in the datarow variable!!)
Someone knows what to do with this?
Thank you!!