Click here to Skip to main content
Click here to Skip to main content

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

By , 25 May 2006
 

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
Software Developer (Senior) MikroKom Yazilim A.S.
Turkey Turkey
Member
c# , vb6 , mssql , oracle , mysql , asp , asp.net developer.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralSimply way to customize report ToolBarmembergeneral.jesiu5 Nov '09 - 8:42 
Get the toolbar from ReportViewer control:
ToolStrip toolStrip = (ToolStrip)reportViewer.Controls.Find("toolStrip1", true)[0]
 
Add new items:
toolStrip.Items.Add(...)
 
Chris
GeneralThanks,memberS. Töpfer28 Sep '09 - 22:20 
Thanks your code helped me a lot!
GeneralRe: Thanks,memberyincekara29 Sep '09 - 1:09 
Your welcome Smile | :)
QuestionHow to invoke the pagesteup dialog box programaticallymemberMember 429011810 Apr '08 - 6:57 
Hi
 
Can any body let me know how to invoke the pagesetup dialogbox in report viewer programatically.
 
Regards
Rajesh
AnswerRe: How to invoke the pagesteup dialog box programaticallymemberyincekara29 Sep '09 - 1:23 
Did you download the source code ?
see frmCmdPageSetup() method.
 
Additionally ...http://www.gotreportviewer.com/EMFPrint.zip[^]
Generalcode licencemembermarsu3622 Dec '07 - 22:29 
Dear yincekara,
I wonder what licence your code is. Can I use codefragments in my own application?
 
yours sincerely,
marsu36
GeneralRe: code licencememberyincekara14 May '08 - 22:11 
Sure. It is open.
GeneralRefreshing the Report Boundsmemberf r i s c h13 Sep '07 - 3:17 
Hello there, nice article i must say.
 
Unfortunately i have another issue for you. After changing the margin-values via PageSetup i can not see any change until i have restarted my Application or at least show the same report in a newly created control.
 
I guess thats because the control doesnt reload the report definitions probably.
 
I have already tried setting the LocalReport.ReportPath again and also reportViewer.RefreshReport but without any success.
 
May i have an advice from you please.
 
Thank you.
GeneralRe: Refreshing the Report Boundsmemberyincekara13 Sep '07 - 3:32 
Sorry. I have no idea.
GeneralRe: Refreshing the Report Boundsmemberf r i s c h13 Sep '07 - 21:33 
I found a Solution for that.
 
You have to call the Reset-Method of the ReportViewer-Control and then reload its data and link all the Events again.
 
This is kinda clumsy but it works.
 
Anyways you did a great job, this article was what i needed.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 25 May 2006
Article Copyright 2006 by yincekara
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid