Problem: 2 BindingSources, 1 DataTable

Mr_Fulano
Mr_Fulano used Ask the Experts™
on
Hi, I'm using VB 2005, WinForms. I have DataGridView on one of my Forms. I use a BindingSource to supply data to the DataGridView as shown in the code below:

Public bs As New BindingSource  '< Declared at the top of my Form.

In the LOAD event I state:

bs.DataSource = Me.dtTable1
DataGridView1.DataSource = bs

All that works fine...

I also have an RDLC report that I display using ReportViewer. I created a BindingSource for that report, because I wanted to filter the data in a different way than in the other BindingSource, so I declared it in my Button_Clicked event as shown below:

Dim bsReport As New BindingSource
bsReport.DataSource = Me.dtTable1
bsReport.Filter = "ProductID = 67"

Although this give me the correct results for my report, it re-filters my DataGridView1 to show only products with ProductID = 67. (Not what I wanted)

I know that both BindingSources are fed by the same DataTable (dtTable1), but why is one BindingSource affecting the other if I'm using "NEW" to declare the second BS? And equally as important, how can I avoid this and still be able to use the Filter option in BS to get the data I need in my report?

Thanks,
Fulano
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


i think the reason is that ur working on the same dataTable
even though ur using different binding source...


game-master

Author

Commented:
Hi Game-Master...yes, I agree. I'm hoping someone will have a solution for allowing 3 BS to work with 1 DT.

Thanks,
Fulano

Author

Commented:
...correction >> for allowing (TWO) 2 BS...not 3. Sorry for the typo.
Most Valuable Expert 2012
Top Expert 2014
Commented:
You are using the New to create the second BS but you are feeding it using the same source of rows (datatable). The filter applied through BS is applied to the datatable hence the problem. Try the following statement after showing the report

Me.dtTable1.DefaultView.RowFilter = ""

Author

Commented:
That worked thank!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial