Search code examples
c#activereports

Activereports PageReport creation by using custom data


I wanna create a page report based on my custom class and my PageReport contains a table inside.

Say for example I have a Customer data class as follow

Class CustomerData 
{
  string name;
  string id;
  string address;
}

and I create a List<CustomerData> CustomerList which contains all my customer data. I want to assign this data as the datasource for my Pagereport. I know In SectionReport we can do like this. But how to assign my list of information to PageReport. Could anybody help me

Ultimately I am expecting a output like something below

----------------------------------------------
|Name       |      ID        |     Address    |
----------------------------------------------
|Name1      |      ID1       |     Address1   |
----------------------------------------------
|Name2      |      ID2       |     Address2   |
----------------------------------------------
|Name3      |      ID3       |     Address3   |
----------------------------------------------

update

ComponentIdInfo is one of the field

enter image description here


Solution

  • Do, something like this:

            this._rptPath = new FileInfo(@"..\..\PageReport1.rdlx");
            this._definition = new PageReport(this._rptPath);
            this._definition.ConfigurationProvider = new GrapeCity.ActiveReports.Configuration.DefaultConfigurationProvider();
    
            this._runtime = new PageDocument(this._definition);
            this._runtime.LocateDataSource += this.runtime_LocateDataSource;
            this.YourViewer.ReportViewer.LoadDocument(this._runtime);
    

    And on your runtime_LocateDataSource event, Add the following code:

    private void runtime_LocateDataSource(object sender, LocateDataSourceEventArgs args)
        {
            object data = null;
            string dataSetName = args.DataSetName;
            string dataSourceName = args.DataSourceName;
    
            if (StringsAreEqual("DataSource1", dataSourceName))
            {
                if (StringsAreEqual("DataSet1", dataSetName))
                {
                    data = CustomerListDataTable;
                }
            }
    
            args.Data = data;
        }
    
        private static bool StringsAreEqual(string str1, string str2)
        {
            return string.Compare(str1, str2, true, CultureInfo.InvariantCulture) == 0;
        }
    

    Please note that you have to create a DataSource named DataSource1 and DataSet named DataSet1 in your page report. And match the column names of DataSet1 to Customer's class public properties.

    To get to the Add DataSource , right click on just outside of your page report (gray area) and select property and look for DataSource in the property window.

    How to Add DataSource/DataSet

    • In the Report Explorer, right-click the Data Sources node and select the Add Data Source option.
    • In the Report Data Source Dialog that appears, select the General page and in the Name field, enter a name like DataSource1.
    • Right click data source node and select the Add Data Set option.
    • In the DataSet Dialog that appears, select the General page and enter the name of the dataset as DataSet1. This name appears as a child node to the data source icon in the Report Explorer.
    • Go to the fields tab and enter your DataSet's fields (columns) there

    Please note that if you cannot find Report Explorer, go to Visual Studios View menu and go to Other Windows.