|
-
Mar 8th, 2010, 05:42 PM
#1
Thread Starter
PowerPoster
[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,
Last edited by blakemckenna; Mar 8th, 2010 at 06:07 PM.
Blake
-
Mar 8th, 2010, 07:26 PM
#2
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.
-
Mar 8th, 2010, 07:41 PM
#3
Thread Starter
PowerPoster
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,
-
Mar 8th, 2010, 07:49 PM
#4
Re: Binding a DataGridView with 2 tables?
 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.
-
Mar 8th, 2010, 08:08 PM
#5
Thread Starter
PowerPoster
Re: Binding a DataGridView with 2 tables?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|