Moriclanuser2000
Moriclanuser2000

Reputation: 11

List of Lists in datagridview

I have a list of employees:

List<Person> Employees;

the class Person has two properties:
a name, and a List-of number of widgets they made each hour(limited to 24 hours)

Now i want to display this array in a datagridview: i guess the display should look something like:

employees, 1,2,3,4,....,24 

anna     , 0,10,5,15,..,5  
jeff     , 1,6,2,......,4

and so on.

right now i just make a datasource=employees binding, and this sucessfully displays the name, but it doesn't even touch the List property. is there some trick to making a list of ints into a property? or maybe i should make a separate property for each hour that will interface with the list?

Upvotes: 1

Views: 972

Answers (1)

Tamir
Tamir

Reputation: 3901

a simple option is to create a "get" property inside the Person class that returns the list of integers as a single string, like you want to output.

public string NumbersList
{
    get
    {
        return string.Join(", ", this.List);
    }
}

and when you bind, use this property instead of the list so it will show the long string you want ("1,3,4")

Upvotes: 1

Related Questions