Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Using collection object as report datasource

leave a comment »

Chorn Chan Reasey, my very first daughter.
Well I am not gonna talk much about her now since I am still at my early stage as a father :)

Today topic is:
“How to pass Generic collection to Report.rdlc DataSource”

Well if you follow the walkthrough in MSDN everything seem to work perfect. However I ran into a situation where I define my object as bellow:

public class Person{
   private string _firstname;
   private string _lastname;

   public string FirstName{
         get{ return _firstname;}
         set{ _firstname = value;}

   public string LastName{
         get{ return _lastname;}
         set{ _lastname = value;}

   public Person(string fname, string lname){
         _firstname = fname;
         _lastname = lname;

okay, nothing wrong it just a normal object definition right?
Then I go

public class PersonList{
   List m_Persons = new List();
   public List Persons{
         get{ return m_Persons;}
   public PersonList(){
         m_Persons.Add(new Person("Chorn", "Sokun"));
         m_Persons.Add(new Person("Yim", "Seiha"));
         m_Persons.Add(new Person("Chorn", "Chan Reasey"));

again it simple once.
Now when I tried to pass PersonList to Report.rdlc I hope that the following statement will do the job:

PersonList list = PersonList();

/* this is not gonna work - how I stuck. */
personBindingSource.DataSource = list; 

/* this is how I should assign it */
DataSource = list.Persons;

Written by Chorn Sokun

October 9, 2006 at 4:52 pm

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: