Data Binding using External Objects

Posted by: fsl on 29 January 2020, 1:46 am EST

    • Post Options:
    • Link

    Posted 29 January 2020, 1:46 am EST

    I’m using this method copied (more or less) from https://www.grapecity.com/componentone/docs/uwp/online-flexreport/DataBindingusingExternalObjects.html

    C1FlexReport _report = new C1FlexReport();
    List<OrderListItem> outstandingOrders = Wibble.Services.OrderService.GetOutstandingOrders(dateFrom: null, dateTo: null);
    using (Stream stream = Services.ReportService.GetFlexReportDefinition("Reports"))
        _report.Load(stream, "Report1");
    _report.DataSource.Recordset = outstandingOrders;
    
    

    The report is found in the assembly at runtime ok but

    _report.DataSource.Recordset = outstandingOrders;
    

    fails with the error

    System.NullReferenceException: ‘Object reference not set to an instance of an object.’

    C1.Xaml.FlexReport.C1FlexReport.DataSource.get returned null.

    DataSource = null. I can’t see where in the docs it shows how to initialize the DataSource. What am I missing?

  • Posted 31 January 2020, 8:38 am EST

    Hi,

    I have attached two applications:

    1. Library_MVVM, this is a library implemented in MVVM pattern.
    2. MVVMLib_UWPFlexRpt, this is an UWP application binding C1FlexReport in code to the data present in above library.

    Please verify your code w.r.t above application and share with us your observations. Hopefully the above samples will help you meet your requirement.

    Thanks & best wishes,

    Ruchir

    Library_MVVM.zip, MVVMLib_UWPFlexRpt.zip

  • Posted 1 February 2020, 11:44 pm EST

    Thank you Ruchir. We can now bind a collection to a report. The key was to set the DataSource of the report in the report designer to Main.

    The report does not show the properties of the collection. How do we access the properties of the collection from within the report designer in order to design the layout of the report and bind controls to collection properties?

  • Posted 3 February 2020, 1:32 am EST

    Hi,

    Glad that you can bind the report to the data source.

    Regarding accessing the properties from report designer, like mentioned over the other case: https://www.grapecity.com/forums/uwp-edition/bind-a-flexreport-to-a-vie#hibefore-confirming-it-to-, I am discussing it with developers and will update you with the information I receive.

    Best wishes,

    Ruchir

  • Posted 15 April 2020, 12:14 am EST

    Hi Ruchir

    Any progress regarding viewing the properties of the viewmodel from report designer? We bind the data source to the report then save the report definition as below but when viewed in the report designer the report definition does not contain the properties of the viewmodel

    _report.Load(stream, "Report1");
    _report.DataSource.Recordset = statementViewModel;
    FileSavePicker picker = new FileSavePicker();
    picker.FileTypeChoices.Add("Files report (*.flxr)", new System.Collections.Generic.List<string>() { ".flxr" });
    picker.SuggestedStartLocation = PickerLocationId.ComputerFolder;
    StorageFile storageFile = await picker.PickSaveFileAsync();
    await _report.SaveAsync(storageFile);
    
    

    We need to be able to see the properties of the viewmodel in the report designer. What are we doing wrong here?

  • Posted 16 April 2020, 2:20 am EST

    Hi,

    In your other query [https://www.grapecity.com/forums/uwp-edition/bind-a-flexreport-to-a-vie#hiit-is-possible-to-do-thi] I posted an application that contained nested properties and showed how to set the report data source to the ViewModel. The application I shared targets UWP and Net4.6 but, C1FlexReportDesigner is released for Net4 and Net4.5.2 so you can’t use C1FlexReportDesigner application distributed with ComponentOne. ComponentOne provides a demo FlexReportDesigner you can find it here: https://www.grapecity.com/samples/c1flexreportdesigner-application

    It uses the same code as C1FlexReportDesigner so you can build it manually for Net6.0.

    *Also when build please add reference to

    System.Reflection.TypeExtensions 4.6.0 nuget package, it is required because Library_MVVM is not a trivial WinForms library.

    Please try the above and if still you face any problem, please share your stripped application for us to investigate.

    Thanks,

    Ruchir

  • Posted 16 April 2020, 5:04 am EST

    Thank you Ruchir. I’m not sure if we are talking about the same thing here. I save a report definition using

    await _report.SaveAsync(storageFile);
    

    I’m not trying to use the designer to connect to the data source. I’m trying to bind the data source in C# then save the report definition with the bound data source so that I can then open it in the designer. When I open the report in the designer I want to see the data source properties so they can be arranged on the report.

    Are you saying the reason I do not see the data source saved with the report when I open that report with the report designer is due to an issue with the report designer?

  • Posted 24 April 2020, 2:38 am EST

    Hello,

    Apologies for the delayed response and kindly neglect my previous response, I had it misinterpreted.

    From what I now understand, you are binding the FlexReport to a data-source in code-behind and saving its report definition. Then, upon loading this report definition in report designer, you expect the designer to show the data-source properties?

    If it is so, I would like to inform you that it is by-design. This is because the data source was assigned in code-behind so the designer would not know the properties of the data-source. It would just be the earlier layout that you had created using the designer.

    If there is something else you are expecting, please elaborate.

    Thanks & regards,

  • Posted 24 April 2020, 4:33 am EST

    Thank you Ruchir. Just to be sure I understand correctly, if we bind the datasource to the report and then save the report as a .flxr file like this

    _report.DataSource.Recordset = statementViewModel;
    await _report.SaveAsync(storageFile);
    

    the report definition does not include the data source? What does SaveAsync do?

  • Posted 25 April 2020, 7:49 am EST

    The method saves the current report definition to a file as mentioned here: https://www.grapecity.com/componentone/docs/uwp/online-flexreport/C1.UWP.FlexReport~C1.Xaml.FlexReport.C1FlexReport~SaveAsync.html

    Thanks,

    Ruchir

  • Posted 25 April 2020, 4:38 pm EST

    When you save a flexreport in the designer it also saves the data source as part of the report definition. Correct?

    A flxr file is an xml file. The DataSource is an element in the xml file

    <DataSources>
      <DataSource>
        <Name>Main</Name>
        <DataProvider>ExternalObject</DataProvider>
        <ConnectionString>D:\TEMP\BUGS\419159\Library_MVVM\Library_MVVM\bin\Debug\Library_MVVM.dll</ConnectionString>
        <RecordSource>Library_MVVM.CustomerViewModel;</RecordSource>
        <RecordSourceType>Text</RecordSourceType>
      </DataSource>
    </DataSources>
    

    The report designer is a UI over creating the report definition in code. We create a report definition file in code then save it. The report definition includes the data source. According to the SaveAsync docs

    This method does not embed pictures and subreports into the output file. It only saves subreport names and saves images in external files.

    The docs say nothing about not saving the data source. If the docs are correct, it should save the data source. Can you please confirm if the docs are correct?

  • Posted 29 April 2020, 4:09 am EST

    Hello,

    Just wanted to update you that we are further investigating this scenario. We will get back to you with more information on this.

    Regards

    Ruchir

  • Posted 30 April 2020, 9:46 pm EST

    You may find this helpful; in our current report writer we do something like

    report.RegBusinessObject(nameof(StatementViewModel));
    await report.SaveAsync(storageFile);
    

    This then creates a report definition file with the data source defined like this

    <StatementViewModel Ref="2" type="Stimulsoft.Report.Dictionary.StiBusinessObject" isKey="true">
      <Alias>StatementViewModel</Alias>
      <BusinessObjects isList="true" count="2">
        <Statements Ref="3" type="Stimulsoft.Report.Dictionary.StiBusinessObject" isKey="true">
          <Alias>Statements</Alias>
          <BusinessObjects isList="true" count="1">
            <Orders Ref="4" type="Stimulsoft.Report.Dictionary.StiBusinessObject" isKey="true">
              <Alias>Orders</Alias>
              <BusinessObjects isList="true" count="0" />
              <Category />
              <Columns isList="true" count="32">
                <value>OrderId,System.String</value>
                <value>OrderNr,System.Int32</value>
                <value>OrderStatus,System.String</value>
                <value>DateDue,System.Nullable`1[System.DateTime]</value>
                <value>DateEntered,System.DateTime</value>
                <value>DateInvoiced,System.Nullable`1[System.DateTime]</value>
                <value>ItemCode,System.String</value>
                <value>ItemDescription,System.String</value>
                <value>NrUnits,System.Int32</value>
                <value>CustomerId,System.String</value>
                <value>AddressLabel,System.String</value>
                <value>FileAs,System.String</value>
                <value>StaffCode,System.String</value>
                <value>CompletedSMSResult,System.String</value>
                <value>CompletedSMSSuccess,System.Boolean</value>
                <value>CompletedSMSFailed,System.Boolean</value>
                <value>Discount,System.Decimal</value>
                <value>UnitPrice,System.Decimal</value>
                <value>ItemTotal,System.Decimal</value>
                <value>Net,System.Decimal</value>
                <value>Tax,System.Decimal</value>
                <value>Total,System.Decimal</value>
                <value>TaxRate,System.Decimal</value>
                <value>Paid,System.Decimal</value>
                <value>Balance,System.Decimal</value>
                <value>JobId,System.String</value>
                <value>DateCollected,System.Nullable`1[System.DateTime]</value>
                <value>DateCompleted,System.Nullable`1[System.DateTime]</value>
                <value>LocationId,System.String</value>
                <value>LocId,System.String</value>
                <value>JobCount,System.Int32</value>
                <value>IsSelected,System.Boolean</value>
              </Columns>
              <Dictionary isRef="1" />
              <Guid>a4053a0c25154955a6ab900a58dc466c</Guid>
              <Name>Orders</Name>
            </Orders>
          </BusinessObjects>
          <Category />
          <Columns isList="true" count="6">
            <value>CustomerId,System.String</value>
            <value>FileAs,System.String</value>
            <value>AddressLabel,System.String</value>
            <value>Days90,System.Decimal</value>
            <value>Days60,System.Decimal</value>
            <value>Days30,System.Decimal</value>
          </Columns>
          <Dictionary isRef="1" />
          <Guid>a6a5adb8413340a28a2e56f3c8a6dad9</Guid>
          <Name>Statements</Name>
        </Statements>
        <LetterheadImage Ref="5" type="Stimulsoft.Report.Dictionary.StiBusinessObject" isKey="true">
          <Alias>LetterheadImage</Alias>
          <BusinessObjects isList="true" count="1">
            <Dispatcher Ref="6" type="Stimulsoft.Report.Dictionary.StiBusinessObject" isKey="true">
              <Alias>Dispatcher</Alias>
              <BusinessObjects isList="true" count="0" />
              <Category />
              <Columns isList="true" count="2">
                <value>HasThreadAccess,System.Boolean</value>
                <value>CurrentPriority,Windows.UI.Core.CoreDispatcherPriority</value>
              </Columns>
              <Dictionary isRef="1" />
              <Guid>979f1616a4f144d8b086ca3a490d0e8d</Guid>
              <Name>Dispatcher</Name>
            </Dispatcher>
          </BusinessObjects>
          <Category />
          <Columns isList="true" count="0" />
          <Dictionary isRef="1" />
          <Guid>cda88f745da7422fa156072ffeb74674</Guid>
          <Name>LetterheadImage</Name>
        </LetterheadImage>
      </BusinessObjects>
      <Category>StatementViewModel</Category>
      <Columns isList="true" count="7">
        <value>DateFrom,System.String</value>
        <value>DateTo,System.String</value>
        <value>Note,System.String</value>
        <value>TaxName,System.String</value>
        <value>TradingName,System.String</value>
        <value>TradingDetails,System.String</value>
        <value>HasLetterhead,System.Boolean</value>
      </Columns>
      <Dictionary isRef="1" />
      <Guid>523644a99f61400ca251f6775be6fd4c</Guid>
      <Name>StatementViewModel</Name>
    </StatementViewModel>
    
    

    There is no need for the developer to specify types, only the viewmodel need be specified and the report designer is able to read the types from the viewmodel.

    The report definition can then be given to our design team for layout. They can see the viewmodel properties in the report designer where they can drag and drop properties onto the design surface.

    That’s what we are hoping to be able to do with Flexreports.

  • Posted 4 May 2020, 5:50 am EST

    Hello,

    I understand your requirement but could you please share a small application demonstrating each step you are following in your application (that is, with the statementViewModel, the code behind where you are setting report’s DataSource, the report definition file etc). If needed, it would help us escalate your requirement and brief the developer more properly and help you effectively.

    Regards,

    Ruchir

  • Posted 31 May 2020, 8:49 pm EST

    My apologies for the delay in responding Ruchir. My company has been on skeleton staff during Covid and I was required to take leave. This is my first day back at work.

    I have created a demo app at

    https://1drv.ms/u/s!AiGVkyOWwr6Jx0jZjvBXMvzqHK03?e=bnXjbp

    The app shows how our current report writer, Stimulsoft, creates a report definition file from the StatementViewModel. The resultant report definition file Statement.mrt is xml.

  • Posted 2 June 2020, 8:22 am EST

    Thank you for the application.

    I am going to forward it for further investigation and will get back to you as soon there is a solution/information.

    Regards,

  • Posted 16 July 2020, 2:19 am EST

    Hello,

    The developer has shared that it is not possible, FlexReport does not support the same scenario as StiReport.

    We are sorry for the inconvenience caused due to this.

    Regards,

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels