Change Report Data Source

  • Thread starter Thread starter William LaMartin
  • Start date Start date
W

William LaMartin

I have report based on a datasource (a tableadapter) that supplies names,
street addresses, cities, etc. to be displayed in a report viewer.

Is there a way in code to modify this report to only show the information
for a certain city provided by the user's entry in a text box?
 
If you have a DataSet and aren't doing data binding, you
can use the inherent DataView class to filter the DataSet.

Dim myDataView = New DataView(myDataSet.Tables("Customers"))
myDataView.Filter = "country = 'Germany'"

If you do this, you will have to use the DataView to display
the data on the report, not the DataSet.

If the report is databound, you can insert a binding source
in between the dataset and the report, and use that to
filter the data.

'GetCustomers fills the Customers table in the Dataset
Dim nwData as CustomersDataSet = CustomersDataSet.GetCustomers()
myReport.DataSource = m_CustomersBindingSource
m_CustomersBindingSource.DataSource = nwData.Customers

Then you can apply a filter to the BindingSource like this:

CustomersBindingSource.Filter = "Country = 'Germany'"

Hope that helps.
Robin S.
 
Back
Top