据我了解,您有一个包含 *.repx 文件的文件夹,但您不知道如何让您的用户选择其中之一。
您可以使用此代码加载组合
public static void loadCombo(ComboBoxEdit control)
{
string path = @"C:\FolderWithRepxFiles\";
string[] filePaths = Directory.GetFiles(path, "*.repx");
control.Properties.Items.Clear();
foreach (string item in filePaths)
control.Properties.Items.Add(System.IO.Path.GetFileNameWithoutExtension(item));
}
然后你可以用这个打印/打印预览报告
public static void PrintPreview(ComboBoxEdit control)
{
string selection = control.SelectedItem as string;
string fullPath = @"C:\FolderWithRepxFiles\" + selection + ".repx";
XtraReport rr = XtraReport.FromFile(fullPath, true);
ReportPrintTool printTool = new ReportPrintTool(rr);
printTool.ShowRibbonPreview();
//printTool.Print();
}
要自定义保存过程,您必须创建自定义命令处理程序。
以下是你的做法:
XRDesignRibbonForm designForm = new XRDesignRibbonForm();
designForm.OpenReport(Your_Report_Object);
XRDesignPanel panel = designForm.ActiveDesignPanel;
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.SaveFileAs, DevExpress.XtraReports.UserDesigner.CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.SaveAll, CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowPreviewTab, CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowHTMLViewTab, CommandVisibility.None);
designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowTabbedInterface, CommandVisibility.None);
if (panel != null)
panel.AddCommandHandler(new SaveCommandHandler(panel));
designForm.ShowDialog();
你需要这个课程
public class SaveCommandHandler : DevExpress.XtraReports.UserDesigner.ICommandHandler
{
XRDesignPanel panel;
string NewPathX = null;
public SaveCommandHandler(XRDesignPanel panel)
{
this.panel = panel;
}
void Save()
{
//Show a form with a textbox and ask the user to give you a name for the report
string fileName = "UserSelectedFileName";
fileName = @"C:\YourDefaultFolder" + fileName + ".repx";
panel.Report.SaveLayout(fileName);
panel.ReportState = ReportState.Saved;
}
public bool CanHandleCommand(ReportCommand command, ref bool useNextHandler)
{
useNextHandler = command != ReportCommand.SaveFile;
return command == ReportCommand.SaveFile;
}
public void HandleCommand(ReportCommand command, object[] args)
{
bool handled = false;
if (!CanHandleCommand(command, ref handled)) return;
Save();
}
}
更多信息:
https://documentation.devexpress.com/#xtrareports/CustomDocument2211
http://www.devexpress.com/Support/Center/Example/Details/E4354
这是你需要的吗?