Search code examples
c#crystal-reports

How to assign Custom class as datasource in crystal report


I created crystal report and through Data-->object i generated the DataSource and i added the fields from generated Datasource. My problem is, how to assign the values to the datasource.

Is anything like grid.DataSource = MyCustomClass is available. I can't access the Database directly [its a remove service]. What is the way to assign the values.

I want some thing like

    class CustomClass
    {
      string name;  
      string number;

       public string Name
       {
       set
       {
         return name;
       }
       }

       public string Number
       {
       set
       {
           return number;
        }
       }

    }
CustomClass custom = new CustomClass ();

custom.Name = "Mohan";
custom.Number = "100";

reportViewer.DataSource = custom ;

Is it anything similar to this is available.


Solution

  • Take a look at this link:

    https://msdn.microsoft.com/en-us/library/ms227595.aspx

    It will show you how this can be done. You can view my answer on this question for an example. How to use Crystal Reports without a tightly-linked DB connection?

    The quick explanation for this is that you should be able to add your custom object into an ArrayList and then use the ArrayList as the datasource. Hope this helps.