5,781,349 members and growing! (23,348 online)
Email Password   helpLost your password?
Languages » C# » How To     Intermediate License: The Code Project Open License (CPOL)

A Workaround to Customizing and Localizing the Microsoft ReportViewer .NET Toolbar

By yincekara

An article about how to customize and localize the Microsoft ReportViewer Toolbar.
C#, Windows, .NET, Visual Studio, Dev

Posted: 25 May 2006
Updated: 25 May 2006
Views: 35,448
Bookmarked: 36 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
14 votes for this Article.
Popularity: 4.58 Rating: 4.00 out of 5
1 vote, 7.1%
1
0 votes, 0.0%
2
1 vote, 7.1%
3
4 votes, 28.6%
4
8 votes, 57.1%
5

ReportViewer Toolbar

Introduction

Microsoft released a new component called ReportViewer based on the new RDL technology. Since this is a new component, there are not enough samples about it. There are many questions about how to localize and customize the ReportViewer toolbar, in some forums. Some developers want to add a help button on it, some people want to localize it for Turkish etc.

What is RDL - Report Definition Language

A report definition contains data retrieval and layout information for a report. Report Definition Language (RDL) is an XML representation of this report definition. RDL is an open schema; developers can extend RDL with additional attributes and elements.

The standard file extension for report definition files is .rdl. Its MIME type is text/xml.

More resources about RDL

Background

The best way to localize and customize the ReportViewer toolbar is to hide it and implement its methods in your own code. This article is simply based on this idea.

Using the code

You can simply hide the ReportViewer toolbar, like this:

repView.ShowToolBar = false;

This will completely hide the ReportViewer toolbar. Then add your own toolstrip and implement the necessary methods.

To find a string in the report:

private bool frmCmdFind()
{
    int found = this.repView.Find(txtSearch.Text, 1);
    if (found > 0)
    {
        btnFindNext.Enabled = true;
    }
    else
    {
        MessageBox.Show("Searched string not found", 
                        "Info", MessageBoxButtons.OK, 
                        MessageBoxIcon.Information);
        btnFindNext.Enabled = false;
    }
    return true;
}

To exporting a report as an Adobe Acrobat PDF file:

private bool frmCmdPdf()
{
    LocalReport lr = this.repView.LocalReport;
    lr.ReportPath = this.repView.LocalReport.ReportPath;
    string outputFile = this.ReportDisplayName + ".pdf";
    File.Delete(outputFile);
    Warning[] warnings;
    string[] streamids;
    string mimeType = "";
    string encoding = "";
    string extension = "";

    deviceInfo = "";

    byte[] bytes = lr.Render("PDF", deviceInfo, out mimeType, 
                             out encoding, out extension, 
                             out streamids, out warnings);

    FileStream fs = new FileStream(outputFile, FileMode.Create);
    fs.Write(bytes, 0, bytes.Length);
    fs.Close();
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p = new System.Diagnostics.Process();

    p.StartInfo.FileName = outputFile;
    p.Start();
    return true;
}

For full implementation, see the source file above.

Conclusion

Microsoft ReportViewer is a powerful component to display your report, and RDL is a good way to implement the reporting features. I believe that in the near future, many RDL designer tools and RDL viewer tools will be available in the market.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

yincekara


c# , vb6 , mssql , oracle , mysql , asp , asp.net developer.
Occupation: Software Developer (Senior)
Company: MikroKom Yazilim A.S.
Location: Turkey Turkey

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralHow to invoke the pagesteup dialog box programaticallymemberMember 42901187:57 10 Apr '08  
Generalcode licencemembermarsu3623:29 22 Dec '07  
GeneralRe: code licencememberyincekara23:11 14 May '08  
GeneralRefreshing the Report Boundsmemberf r i s c h4:17 13 Sep '07  
GeneralRe: Refreshing the Report Boundsmemberyincekara4:32 13 Sep '07  
GeneralRe: Refreshing the Report Boundsmemberf r i s c h22:33 13 Sep '07  
GeneralRe: Refreshing the Report Boundsmemberyincekara22:58 13 Sep '07  
Generalshowing report in report viewer without using smart tagsmemberMeSiddy7:37 16 Aug '07  
GeneralRe: showing report in report viewer without using smart tagsmemberyincekara8:50 16 Aug '07  
QuestionReportviewer Helpmemberabraylyan16:00 11 Mar '07  
AnswerRe: Reportviewer Helpmemberyincekara22:47 11 Mar '07  
GeneralReportViewer problemmemberKschuler9:31 29 Jan '07  
GeneralRe: ReportViewer problemmemberpolymorphism3:32 8 Feb '07  
GeneralRe: ReportViewer problemmemberKschuler3:54 9 Feb '07  
GeneralRe: ReportViewer problemmemberAeroday7:16 19 Jul '07  
GeneralTurkish languagememberMaksi23:25 20 Nov '06  
GeneralRe: Turkish languagememberyincekara23:58 20 Nov '06  
GeneralRe: Turkish languagememberyincekara1:03 12 Feb '07  
Generallocalization [modified]memberlemravec9:16 14 Aug '06  
GeneralRe: localizationmemberpolymorphism0:26 21 Aug '06  
QuestionAnother approachmemberKoru.nl0:31 2 Jun '06  
AnswerRe: Another approachmemberyincekara2:20 2 Jun '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 25 May 2006
Editor: Smitha Vijayan
Copyright 2006 by yincekara
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project