I get this error that I don't know how to properly prevent it from happening:
Cannot bind to the property or column SomeField on the DataSource.
Parameter name: dataMember
I'm including a zipped up project I created that simulates what is happening in my much larger application.
I have created two Data Source classes, and embedded Data2Source member object inside of Data1Source class.
I then added Data1Source object to Data Sources tool tab via wizard.
When I run this tabcontrol form, if I click on the Tab2 without having items in my Data2Source's list, I get this error and I don't know how to properly handle this when there are not yet items in its list. If I have at least one item in the Data2Source's List, I have no problem.
"SomeField", from the error message above, is a Property in Data2Source and is bound to a control on Tab2.
The idea is that user could create several Data1Source List items, each of them having 0 - many Data2Source List items. Data2Source List items cannot exist without corresponding item existing in the Data1Source List.
To create a Data2Source List item and see it run without error, uncomment the dataMgr.data2.Add(new Data2ListItem("Item 4", "someField text"));
in the Form1_Load event:
private void Form1_Load(object sender, EventArgs e)
{
dataMgr = new DataManager();
data1SourceBindingSource.DataSource = dataMgr.data1Source;
for (int i = 0; i < dataMgr.data1.Count; i++)
comboBox1.Items.Add(dataMgr.data1[i].Key);
//////////////////////////////////////////////////////////////////////////////////
// This line of code will stop the Exception.
// As long is there is at least one Item in the data2.List, no binding error occurs.
// dataMgr.data2.Add(new Data2ListItem("Item 4", "someField text"));
//////////////////////////////////////////////////////////////////////////////////
comboBox1.SelectedIndex = 0;
}
If you uncomment out that line above that adds 1 item to Data2Source's List, you can switch to Tab2 and no problem; and you will also see you can change the combobox selection on the form and the Data Source binding to controls is also working.
Don't try to enter data in the textboxes because I created this test project only to resolve this particular issue I am having and I have not implemented or tested this project for other purposes.
Thanks for helping.