我试图弄清楚如何在用户点击新报告或任何新报告时,在DevExpress用户数据报告中将DataSource
设置为默认值设计器。
现在,我在Form_Load
加载的空白报告已经DataSources
就好了,但只要我点击新报告,它们就会消失。< / p>
我已经用谷歌搜索并关注了文档,但它们似乎都是为了打开一份特定的报告(如上所述)。
有人可以帮忙吗?
答案 0 :(得分:1)
<强> 0。 ICommandHandler界面
您需要通过实现ICommandHandler
接口来处理ReportCommand.NewReport
命令。您必须将实现此接口的对象传递给XRDesignMdiController.AddCommandHandler
方法。您可以根据要使用的表单类型从XRDesignMdiController
属性或ReportDesignTool.DesignForm.DesignMdiController
属性获取ReportDesignTool.DesignRibbonForm.DesignMdiController
对象。
这是一个例子:
Private Sub ShowReportDesigner()
Dim tool As New ReportDesignTool(CreateReport)
Dim controller = tool.DesignRibbonForm.DesignMdiController
Dim handler As New NewCommandHandler(controller, AddressOf CreateReport)
controller.AddCommandHandler(handler)
tool.ShowRibbonDesigner()
End Sub
Private Function CreateReport() As XtraReport
Dim report As New XtraReport
report.DataSource = YourDataSourceObjectHere
Return report
End Function
Public Class NewCommandHandler
Implements ICommandHandler
Private ReadOnly _controller As XRDesignMdiController
Private ReadOnly _createReport As Func(Of XtraReport)
Public Sub New(controller As XRDesignMdiController, createReport As Func(Of XtraReport))
_controller = controller
_createReport = createReport
End Sub
Public Function CanHandleCommand(command As ReportCommand, ByRef useNextHandler As Boolean) As Boolean Implements ICommandHandler.CanHandleCommand
useNextHandler = command <> ReportCommand.NewReport
Return Not useNextHandler
End Function
Public Sub HandleCommand(command As ReportCommand, args() As Object) Implements ICommandHandler.HandleCommand
_controller.OpenReport(_createReport())
End Sub
End Class
<强> 1。 DesignPanelLoaded事件
另一种方式是订阅XRDesignMdiController.DesignPanelLoaded
事件。在这种情况下,您可以检查已加载面板中DataSource
报告的位置为空,并将其设置为您的数据源
这是一个例子:
Private Sub ShowReportDesigner()
Dim report As New XtraReport
report.DataSource = YourDataSourceObjectHere
Dim tool As New ReportDesignTool(New XtraReport)
Dim controller = tool.DesignRibbonForm.DesignMdiController
AddHandler controller.DesignPanelLoaded, AddressOf mdiController_DesignPanelLoaded
tool.ShowRibbonDesigner()
End Sub
Private Sub mdiController_DesignPanelLoaded(ByVal sender As Object, ByVal e As DesignerLoadedEventArgs)
Dim panel = DirectCast(sender, XRDesignPanel)
Dim report = panel.Report
If IsNothing(report.DataSource) Then
report.DataSource = YourDataSourceObjectHere
End If
End Sub