none
Microsoft Report Viewer: ReportViewer.Find() method not working as expected RRS feed

  • Question

  • So I happily had my VS2005 DatagridView exporting to Excel, until I upgraded to VS2008 and it broke. Seems it doesn't recognize "Excel.AddMissing..." anymore. Sigh...

    So I created a MS ReportViewer, bound to a bindingsource (which has a SQL Server procedure as its source), added a tableadapter (which really needs to be pointed out in the MSDN or else you get no data).

    My form that hosts the reportviewer has two text boxes (txtHoleCoord, and txtSiteCoord), and one date field. Based on the user typing in a search string in either of the boxes, and setting the date, the results should update immediately as he types. The old DataGridView used a filter on the binding source, and was lightening fast. The date is set to default when the app starts, and the user can change it.

    Unfortunately, using the same bindingsource filter code has no effect on the data returned - the user gets all rows in the data table. I also tried using the Find(....) method which resulted all rows returned.

    Here's the old code (C#) that worked with the bindingsource. This particular code is to select the Site, and note that the this.txtHoleCoord.Text = "" is to reset the selection for the Hole. The user gets to search by either text box entries, not both. The code for the Hole selection is identical, except resets the Site textbox to "" .

    private void txtSiteCoord_TextChanged(object sender, EventArgs e) // doesn't work - results = all rows in report viewer returned
            {
                this.pPrefCoordsBindingSource.RemoveFilter(); // report binding source
                this.txtHoleCoord.Text = "";
                this.txtSiteCoord.Refresh();
                this.pPrefCoordsBindingSource.Sort = "Site ASC";
                this.pPrefCoordsBindingSource.Filter = "Site like '" +
                            this.txtSiteCoord.Text.ToString() + "%' and DrillDate >= '" +
                            this.dtFilterDateView.Value.ToShortDateString() + "'";
           } // End


    Tried this code without the bindingsource filter: //doesn't work - results =  all rows in report viewer returned

                this.reportViewer1.Find("Hole like '" +
                            this.txtHoleCoordFilter.Text.ToString() + "%' and DrillDate >= '" +
                            this.dtFilterDateView.Value.ToShortDateString() + "'", 1);
                this.reportViewer1.RefreshReport();

    ...and when the user inputs text in the txtHoleCoord box, the report refreshes, and again, all rows are returned - not just the filtered ones.

    Notice that I need to query using the 'Like' syntax - the "Find" feature on the menubar doesn't do the job.

    Seems like the reportviewer is ignoring the bindingsource??

    Any clues would be +=1 more than I have.

    Thanks
    Tuesday, December 30, 2008 9:21 PM

Answers

All replies

  • Hi Glen,

    Yes the ReportViewer is not using the BindingSource correctly. This is a bug in the ReportViewer that we have addressed for the next version. A work around in the mean time would be to create a new datasource with the new query that incorporates the filtering, and set this to be the report's datasource. In other words, get a new set of data from your database with the database doing the filtering.


    The Find() method does not use a SQL-like syntax. It takes in a string and searches for that literal string in the report, and sets the report to the page it was found on.

    http://blogs.msdn.com/magreer
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, December 30, 2008 11:21 PM
  • Matt - wont let me reply to your post so replying to mine

    So if I read you correctly, I need to pass the query parameter back to the server, and 'repopulate' the bindingsource with the user filtered data ? Wouldn't that do the same as now - ie the current changes to the bindingsource are ignored by the report - will the new data be read correctly? Or am I not understanding what data source to bind to?

    By the way - any idea why when using VS 2008 my export to Excel blows up? The old code is:

    Excel.Application excel = new Excel.Application ();

                    Excel._Workbook oWB;
                    Excel._Worksheet oWS;
                    oWB = (Excel._Workbook)(excel.Workbooks.Add ( Missing.Value )); // Boom! Blows up

    I tried adding the Excel 12 COM resource to the project - no difference. I had Excel 10 before, but it is not in the new resource list. Would rather use my code tied to a datagridview than a report. Hmm...Can you bind a report to a datagridview?

    Thanks

    Glen
    Wednesday, December 31, 2008 2:07 AM
  • Oh hey, forgot to ask.

    How do you programmatically bind a MS ReportViewer to a data source? Seems that I can only do it thru the Reportviewer object using the "Bind..." selection on the popdown menu.

    Thanks

    Glen
    Wednesday, December 31, 2008 2:29 AM
  • There is another way to work around the BindingSource filter problem.  Take a look at this forum post for details: http://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/e91949c1-5426-4796-9157-732f96466ea4
    • Marked as answer by _Glen Wednesday, December 31, 2008 4:56 AM
    Wednesday, December 31, 2008 2:50 AM
    Moderator
  • Yazzzaa!

    Works like champ!

    Thanks

    Glen
    Wednesday, December 31, 2008 4:56 AM