Ticket T337192
Visible to All Users

How to add a report based on an object collection into XAF

created 9 years ago (modified 9 years ago)

I really need clear step by step instructions on how to do this.
I have looked back through the posts I have made in the last few weeks but I am coding in circles.

I wrote myself some long instructions in the comments at
https://www.devexpress.com/Support/Center/Question/Details/T317718

but they are failing me.

I noted that I need to use the report designer to set the bindingsource.datasource property to the business object that I want to report on.

I looked up a report that I had got working but the object is no longer visible in the  report designer ( when I click the menu in the top left corner of the designer )

In the designer code I see that the correct binding is set  however I should not have to edit generated code to get my new report.

[Update]
Here is the structure of my business object

C#
public class SPResultString { public string Result { get; set; } }

Here is my Reports dbContext

C#
public class ReportsDB : jtDbContext { public IList<SPResultString> CancelOrders() { return GetSpResults("aaCancelTestOrders"); // returns 1 record } // etc

I have made the ReportDataV2_ListView accessible via a navigation item in my project and run the report from an action in a controller.
Here is my Action method

C#
private void actRunReport_Execute(object sender, SimpleActionExecuteEventArgs e) { var report = (ReportDataV2)e.CurrentObject; if (report == null) { return; } using (var db = new ReportsDB()) { if (report.PredefinedReportType.Name.Contains("ClearTestOrders")) { var rep = new ClearTestOrders(); var xtraRep = (XtraReport)rep; xtraRep.DataSource = db.CancelOrders(); xtraRep.ShowPreviewDialog(); } } // etc.

Here is me trying to figure out what options to put in.
I cant work out how to add SPResultString as the bound field

http://screencast.com/t/4saVVuks5

Show previous comments (6)

    The UI now works the way I want, but how do I set it up to get there ?  http://screencast.com/t/P4KMCwopPeW

    Dennis Garavsky (DevExpress) 9 years ago

      Hello Kirsten,

      Most likely your report shows no data because your newly created ReportsDB does not return any data from the CancelOrders method. Would you please verify this while debugging in Visual Studio?

      In an XAF application it is best to instantiate an EFObjectSpace  and then call your stored procedures through its ObjectContext property. You can find more information on this method in MSDN, e.g.:
      https://social.msdn.microsoft.com/Forums/en-US/a7e15e64-5724-44ce-a047-d256424a1e7f/how-to-call-stored-procedure-from-entity-framework?forum=adodotnetentityframework

      >>I have it working now , using the trick of editing the designer generated code.
      >>The UI now works the way I want, but how do I set it up to get there ?  http://screencast.com/t/P4KMCwopPeW
      Please submit a separate ticket on the .NET | XtraReports product and attach your problematic sample project so we can research your exact situation and provide the best technical solution. Thanks in advance.

        Thanks for your answer Dennis.  Once I realized that my question was really about how to report on a collection of objects I was able to work out the answer.  The fact that the data originally came out of a stored procedure got me side tracked.  It is a bit of work to create the correct data object for the stored procedure results.  The only shortcut I know is to use the Import Function feature inside the EF Model First (.EDMX ) approach.

        Answers

        created 9 years ago

        Step 1 )
        From the Project Menu select Add New Datasource to start the Data Source Configuration Wizard
        In the Data Source Configuration Wizard the first question is
        "Where will the application get the data from?"
        Select Object,
        Click Next
        Locate object you want to report on in my case Module.BusinessObjects.SPResultString
        Click Finish

        Step 2 )
        Select Add New Item and use the Report Wizard
        Select Empty Report
        Click Finish

        Step 3 )
        Click the Report Tasks Icon in the top left of the report designer
        Select DataSource
        Then expand out the project objects and select the object you want to report on.
        Then select  XtraReports from the Visual Studio Menu
        Then select Field List to select fields for the report.

        http://screencast.com/t/R70fItkP30yq

        Step 4) The code in the question shows how the object collection can be passed into the report for it to use.

          Comments (1)

            Note to self regarding pivotGrids

            If there is a PivotGrid in the report the following works to set the datasource of the pivotgrid

            C#
            xtraRep.DataSource = spResult.DataSource(paramObjects); var xrGrid = GetGridControl(xtraRep); if (xrGrid != null) { xrGrid.DataSource = xtraRep.DataSource;} private XRPivotGrid GetGridControl(XtraReport xtraRep ) { const string controlName = "xrPivotGrid1"; var controls = xtraRep.Controls; foreach (XRControl ctrl in controls) { var pivotControl = ctrl.FindControl(controlName, true); if (pivotControl == null) continue; return pivotControl as XRPivotGrid; } return null; }

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.