Change behavior of save button in Viewer

Stimulsoft Reports.NET discussion
Post Reply
meukoh
Posts: 6
Joined: Tue Jun 15, 2010 5:11 pm

Change behavior of save button in Viewer

Post by meukoh »

I need to use my own function to export the report data to XML because some clients use a different XML structure than the one outputed by Stimulsoft.

In the Viewer, when the user click Save -> XML File, choose a file name and location, then press Save, is there a way to interrupt the save event, cancel it and instead call my own function so I can create the XML file myself?

Thanks.
Andrew
Posts: 4109
Joined: Fri Jun 09, 2006 3:58 am

Change behavior of save button in Viewer

Post by Andrew »

Hello,

Could you, please clarify your issue. Do you want make your own export to xml on the base of our DataSet or do you want to realize it from scratch?

Thank you.
meukoh
Posts: 6
Joined: Tue Jun 15, 2010 5:11 pm

Change behavior of save button in Viewer

Post by meukoh »

I would prefer to realize it from scratch.

I only want to use the "Save -> XML File" button already in the viewer because adding other buttons would confuse the user.

Thank you.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Change behavior of save button in Viewer

Post by Jan »

Hello,

You can use ProcessExport event of StiViewerControl. Please add your own event handler to this event. Default event handler is:

Code: Select all

protected virtual void OnProcessExport(object sender)
		{
			StiExportService service = sender as StiExportService;
			service.Export(CurrentReport, null, false);
		}
You need add check for StiXmlExportService.

Thank you.
meukoh
Posts: 6
Joined: Tue Jun 15, 2010 5:11 pm

Change behavior of save button in Viewer

Post by meukoh »

Thanks for this answer. This is my event handler:

Code: Select all

        private void OnProcessExport(object sender, EventArgs e)
        {
            StiExportService service = sender as StiExportService;
            
            if (service is StiXmlExportService)
            {
                MySaveToXml();
            }
            else
            {
                service.Export(_stiReport, null, false);
            }
        }
It works but I have a hard time getting Stimulsoft to use it.

I saw that my StiReport object have ViewerControl and ViewerForm properties but they are always null, and creating new StiViewerControl or StiViewerForm doesn't seem to work.

The only way I found for Stimulsoft to use my new handler is this:

Code: Select all

_stiReport.Show();

 ((StiViewerForm)StiViewerForm.ActiveForm).ViewerControl.ProcessExport += new EventHandler(OnProcessExport);
However this is bad since the ActiveForm is easy to change for the user and can lead to NullReferenceExceptions.

Is there another way to access the StiViewerControl and StiViewerForm objects used by my StiReport object to show the reports?

Thank you.
Jan
Posts: 1265
Joined: Thu Feb 19, 2009 8:19 am

Change behavior of save button in Viewer

Post by Jan »

Hello,

You need create your own form with StiViewerControl to use this event of viewer.

Thank you.
Post Reply