Replacing the "Open" and "Save" dialogs
If you decided to store a report in the database, you may need to change the designer in such a way that it can open and save reports from/to a database. That is, you need to replace standard "Open" and "Save" dialogs with your own dialogs that work with database. To do this, use the FastReport.Utils.Config.DesignerSettings
global class (see the Configuring the FastReport environment). This class has the following events:
Event CustomOpenDialog
Occurs when the report designer is about to show the "Open" dialog.
In the event handler, you must display a dialog window to allow user to choose a report file.
If dialog was executed successfully, you must return e.Cancel = false
and set the e.FileName
to the selected file name.
The following example demonstrates how to use this event:
private void CustomOpenDialog_Handler(object sender, OpenSaveDialogEventArgs e)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
dialog.Filter = "Report files (*.frx)|*.frx";
// set e.Cancel to false if dialog
// was succesfully executed
e.Cancel = dialog.ShowDialog() != DialogResult.OK;
// set e.FileName to the selected file name
e.FileName = dialog.FileName;
}
}
Event CustomSaveDialog
Occurs when the report designer is about to show the "Save" dialog.
In the event handler, you must display a dialog window to allow user to choose a report file.
If dialog was executed successfully, you must return e.Cancel = false
and set the e.FileName
to the selected file name.
The following example demonstrates how to use this event:
private void CustomSaveDialog_Handler(object sender, OpenSaveDialogEventArgs e)
{
using (SaveFileDialog dialog = new SaveFileDialog())
{
dialog.Filter = "Report files (*.frx)|*.frx";
// get default file name from e.FileName
dialog.FileName = e.FileName;
// set e.Cancel to false if dialog
// was succesfully executed
e.Cancel = dialog.ShowDialog() != DialogResult.OK;
// set e.FileName to the selected file name
e.FileName = dialog.FileName;
}
}
Event CustomOpenReport
Occurs when the report designer is about to load the report.
In the event handler, you must load the report specified in the e.Report
property from the location specified in the e.FileName
property.
The latter property contains the name that was returned by the CustomOpenDialog
event handler.
It may be the file name, the database key value, etc. The following example demonstrates how to use this event:
private void CustomOpenReport_Handler(object sender, OpenSaveReportEventArgs e)
{
// load the report from the given e.FileName
e.Report.Load(e.FileName);
}
Event CustomSaveReport
Occurs when the report designer is about to save the report.
In the event handler, you must save the report specified in the e.Report
property to the location specified in the e.FileName
property.
The latter property contains the name that was returned by the CustomSaveDialog
event handler.
It may be the file name, the database key value, etc. The following example demonstrates how to use this event:
private void CustomSaveReport_Handler(object sender, OpenSaveReportEventArgs e)
{
// save the report to the given e.FileName
e.Report.Save(e.FileName);
}