次の方法で共有


Why is ReportViewer Ignoring BindingSource Operations?

I’ve seen several posts in the Report Viewer forum from frustrated users who are trying to use a BindingSource as a data source to the ReportViewer in local mode.  Problems typically manifest when setting sorting or filtering options on the BindingSource object, but those operations are not reflected in your report.  So what’s going on?

The short answer is that it’s a bug in the ReportViewer.  When presented with a BindingSource, the viewer is reaching in and referencing the underlying data source, which bypasses any transformations the BindingSource applies.  So instead of displaying filtered data, the report viewer still shows you the raw data in the report.

We’ve fixed this bug for the next release of the viewer.  But until that is released, there’s an easy way to code around this problem.  Since the viewer uses the underlying data source rather than the transformed output, adding an extra BindingSource layer fixes the problem.  In you form load event, you can add the following code:

BindingSource tempBindingSource = new BindingSource(this.OriginalBindingSource, "");
this.reportViewer1.LocalReport.DataSources[0].Value = tempBindingSource;

You will need to replace "OriginalBindingSource" and "reportViewer1" with the equivalent names of objects on your form.  The index into the DataSources collection may also be different, depending on your report.

With this workaround, when the ReportViewer processes the report, it sees the tempBindingSource as the data source.  Our bug causes the viewer to reference the underlying data source of tempBindingSource, which is the filtered output from the original BindingSource object.  As a result, you get the expected data in the report.

On a side note, I want to mention that this bug was first reported to us via Microsoft Connect.  If you believe you are running into a bug in the report viewer or have a request for a new feature, Connect is a great way to contact us.  We track these issues directly and the site allows us to communicate back and forth if we have trouble reproducing the problem.  It also allows you to vote on existing feature requests or bugs to help us prioritize the work.

Comments

  • Anonymous
    February 06, 2009
    I was actually wanting to post to one in December, but it is disabled.  Where is the report viewer and ability to create reort in VS C# express?
  • Anonymous
    February 15, 2009
    The only express sku that has a report viewer design time add-on is the web developer express sku.  The run time redistributable, however, will work with any sku.