我正在使用 DevExpress 工具在 C#.Net 中做项目。我创建了一些模板/报告 (XtraReport) 并创建了按钮来单独显示来自此 link 的模板.
现在我需要获取所有模板名称并希望在 DropDown 中显示,最终用户可以单独选择和查看每个模板 ??
我可以使用此代码获取从设计器创建并从 bin>Debug>UserTemplates .repx 格式文件外部存储的模板,并存储在下拉列表中并在预览中显示。
printBarManager1.PrintControl = printControl1;
XtraReport RptObj = XtraReport.FromFile(Application.StartupPath + @"\UserTemplates\" + CBL_QuoteTempList.EditValue + ".repx", true);
RptObj.CreateDocument();
printControl1.PrintingSystem = RptObj.PrintingSystem;
但我需要获取我创建的模板吗?如何获得 ?从哪里得到?建议我或帮助我解决这个问题。
提前致谢。斯里哈里
请您参考如下方法:
据我了解,您有一个包含 *.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
这是你需要的吗?
