Chorn Sokun’s Weblog

try { divide and conquer; } catch { keep it simple!; } finally { nothing is impossible; }

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