将DataSource绑定到新的DevExpress报表设计器?

时间:2015-04-16 19:33:19

标签: vb.net devexpress devexpress-windows-ui

我试图弄清楚如何在用户点击新报告或任何新报告时,在DevExpress用户数据报告中将DataSource设置为默认值设计器。

现在,我在Form_Load加载的空白报告已经DataSources就好了,但只要我点击新报告,它们就会消失。< / p>

我已经用谷歌搜索并关注了文档,但它们似乎都是为了打开一份特定的报告(如上所述)。

有人可以帮忙吗?

1 个答案:

答案 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