Using a List of a Custom Class Object as a Data Source for a Crystal Report

I am trying to find a way to create a report using my own custom class.

I found the links:

1.) How to work in Crystal Report with an object data source?

2.) Use a .net object as a data source in Crystal Report 2008

3.) A binding object with a list <> to a Crystal report

4.) How to designate a custom class as a data source in a Crystal report

They were very useful, but I was stuck at the first stage when developing the report, since my own class property was not listed in the list of fields of the crystal report on crystal design.

An example of my custom class:

class UserType public property UIN as integer... public property Title as string... end class class User public property UIN as Integer... public property Name as string... public property Password as String... public property Type as UserType... end class 

When I add class objects to the Crystal report, I do not get the usertype field from the user class in the field list.

So how can I add a usertype field to my list of fields? Or do I need to take a different approach?

Edit:

The reason I wanted to use it as I am:
1.) Displays the form in which the user can enter a keyword
2.) the program filters records by keywords using LINQ
3.) when the user clicks the print button, I want to set the filtered records as the data source of my report

+6
source share
3 answers
  • Create your own dataset with columns matching your class, and assign a dataset to your report normally.
  • When you have an object class loaded with data and / or filtered using values ​​entered by users (filtered with linq, etc.) do the following:

     dim yourDataset as dataset ' this is your typed dataset Dim dr As datarow For n As Integer = 0 To yourClass.Count - 1 dr = yourDataset.tables("TableName").NewRow dr("ColumnNameOne") = yourClass(n).PropertyName dr("ColumnNameTwo") = yourClass(n).PropertyName yourDataset.tables("TableName").Rows.Add(dr) Next ' bind the datasource crystalreport.SetDatasource(ds) 
+1
source

You can try to serialize the object in XML, provide an XSD, and then use the Crystal Report XML driver to connect to it. The report will β€œsee” the object as two tables: one for the User and one for the UserType. You include both tables in the report and link the tables using the internal_id field.

0
source

Why not assign a strongly typed dataset to your report and save a lot of problems?

0
source

Source: https://habr.com/ru/post/888916/


All Articles