[RESOLVED] Binding a DataGridView with 2 tables?
This is a 2-part question.
Part 1:
I have a datagridview who's datasource is a BindingSource. The problem that I need to resolve is that the DGV has 6 columns, 5 of which come from the same database table, while the other column comes from another database table. Is there anyway of configuring the BindingSource that will make it contain all 6 columns?
Part 2:
The same grid in Part 1 works in the way that when a user selects a row, textboxes and comboboxes are populated with the DGV Row of data in order for the data to be modified. When the user makes any changes, this modified data needs to update the DGV row or BindingSource. How do I associate the changed values back to the BindingSource or the DGV?
Thanks,
Re: Binding a DataGridView with 2 tables?
1. You can only bind to a single object. Your DataGridView binds to a single BindingSource and your BindingSource binds to a single DataTable. If you want that DataTable to contain data from multiple database tables then that's what your query is for. Simply write the appropriate join in your SQL code.
2. You simply bind your other controls to the same BindingSource. Any changes in the TextBoxes, etc, updates the data source and that updates the grid. It's all automatic, which is the whole point of data-binding.
Re: Binding a DataGridView with 2 tables?
jmc,
For part 1, I actually tried that before I read your response and that worked. As far as part 2, that worked really well. For some reason, I like to write the SQL statements and see the code that produces the output. Do you know of a good reference book about DataBinding?
Thanks,
Re: Binding a DataGridView with 2 tables?
Quote:
Originally Posted by
blakemckenna
Do you know of a good reference book about DataBinding?
I'm sure most books that cover WinForms cover it to some degree but I learned from MSDN, other web resources and by doing.
Re: Binding a DataGridView with 2 tables?