Monday, October 09, 2006

Using collection object as report datasource

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:

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

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();
personBindingSource.DataSource = list; // this is not gonna work - how I stuck.
personBinddingSource.DataSource = list.Persons; // now it work - right because this is where the actual collection hidden.