Add Control To Crystal Report Viewer Toolbar with vb.net

Hey everyone. Not a lot to report today. I have almost finished the email class within our application and I have to say it is turning out pretty nice.

I hate Crystal Reports, lets be clear on this. It is a plague that has cursed the earth. But unfortunately someone wanted me to add a control to the Crystal Reports viewer toolbar on an existing application. I like to write my own custom reporting using MS Word or Excel. But we don’t get to like what we do all the time.

So here it is……make it a great day!

Private Sub DoWork(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MessageBox.Show("Do your code here")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each ctrl As Control In CrystalReportViewer1.Controls
            If TypeOf ctrl Is Windows.Forms.ToolStrip Then
                Dim btnNew As New ToolStripButton
                btnNew.Text = "My Button"
                CType(ctrl, ToolStrip).Items.Add(btnNew)
                AddHandler ctrl.Click, AddressOf DoWork
            End If
        Next
    End Sub

 

 

Advertisements
  1. #1 by Jennifer on October 17, 2008 - 10:47 am

    I second you on Crystal!  But, like you said, we can\’t always use the things we prefer. 

  2. #2 by Peter on March 18, 2009 - 8:36 am

    Thanks for the snippet of code.Its always nice to get help!

  3. #3 by chawan on June 29, 2009 - 5:03 am

    hi, if i want add control in CRV on web by C#.net .Can you help me,thank.

  4. #4 by SickBoy on May 21, 2010 - 11:21 am

    Hello — I found your code useful, but with one modification:Private Sub DoWork(ByVal sender As System.Object, ByVal e As System.EventArgs) MessageBox.Show("Do your code here") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each ctrl As Control In CrystalReportViewer1.Controls If TypeOf ctrl Is Windows.Forms.ToolStrip Then Dim btnNew As New ToolStripButton btnNew.Text = "My Button" CType(ctrl, ToolStrip).Items.Add(btnNew) AddHandler btnNew.Click, AddressOf DoWork End If Next End SubThe 4th line from the bottom replaces your "AddHandler ctrl.Click, …" with "AddHandler btnNew.Click, …" If you do not make this replacement, all of the controls in the ToolStrip perform the DoWork sub when pressed, which was not desired in my case.Please know i did not post this to criticize, only to help others wanting to use it! Thanks for the cool code!

  5. #5 by Kelly on May 24, 2010 - 4:58 pm

    SickBoy, that you for the comments and the code snipet. Your modification is noted and appreciated.

  6. #6 by Geert Demuynck on December 6, 2011 - 7:37 am

    A million times and more thanks for the code snipet. This is what I was looking for.

  7. #7 by Kyle on February 26, 2012 - 7:51 am

    Hello, how to add a crystal report viewer control to toolbar or tab under report tool. Thanks in advance.

  8. #8 by migules on February 26, 2012 - 7:53 am

    Thank you so much for sharing this crystal report information, I will try this on my project.

  9. #9 by Redf0x on March 5, 2015 - 12:54 am

    Thank You.. your code is best….

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: