Reputation: 17653
I am trying to find way to design a report using my own custom class.
I found links:
1.) How to work in Crystal Report with Object Data Source?
2.) Use .net object as data source in Crystal Report 2008
3.) Binding object with List<> to Crystal Report
4.) How to assign Custom class as datasource in crystal report
They were quite helpful, but I have been stuck in the first step while designing report as my custom class's property is not listed in field list of crystal report design view.
Sample 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 my class objects to crystal report I do not get the usertype field from users class in field list.
So how can I add usertype field to my field list? Or do I have to take another approach?
Edit:
The reason i wanted to use it as i am:
1.) Showing a form where user can type keyword
2.) program filters the records as per keyword using LINQ
3.) when user clicks the print button, I want to set the filtered records as datasource of my report
Upvotes: 6
Views: 6219
Reputation: 327
When you have your object class loaded with data, and/or filtered with values entered by users (filtered with linq etc..) do this:
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)
Upvotes: 1
Reputation: 4023
Why don't you assign a strongly typed dataset to your report and save yourself lots of trouble?
Upvotes: 0
Reputation: 26262
You could try serializing the object to XML, supply an XSD, then use Crystal Report's XML driver to connect to it. The report will 'see' the object as two tables: one for the User and one for UserType. You'll include both 'tables' in the report and link the tables using the internal_id field.
Upvotes: 0