Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using list of custom Class object as data source for crystal report

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

like image 608
KoolKabin Avatar asked May 24 '11 14:05

KoolKabin


1 Answers

  • Create your dataset with the columns matching your class, and assign the dataset to your report normally.
  • 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)
    
like image 165
gustav12 Avatar answered Oct 13 '22 20:10

gustav12