C# - DataSets and Data Binding in multiple Forms
I have the following scenario:
- A database
- A DataSet that is filled by the database
- Two Forms:
- The first Form contains a ComboBox that s开发者_运维问答hows a certain set of categories. The ComboBox is binded to a DataTable "categories" in the DataSet.
- The second Form is supposed to be a category manager where you can add, edit and delete categories from the database. It contains an editable DataGridView that is also binded to the same DataTable.
Now, when I change the DataSet in the second Form, both the DataGridView and the database are being updated, however the ComboBox in the first Form is not. What's the best way to keep it up to date? Somebody on the MSDN forums suggested something like that:
public void updateDataBindings()
{
// doesn't seem to do anything:
categoriesComboBox.DataSource = categoriesBindingSource;
}
This method of Form1 would be called whenever the DataGridView in Form2 changes. The ComboBox however remains unchanged.
Greetings!
wibYou've databound the dataset to the combobox, but have you also told the combobox what it's datamembers are, etc. so that it knows what value to watch?
精彩评论