I have a classroom full of students and I've tracked which activity they've done and what score they achieved on each activity using this code:
public class TrackActivity
{
public String StudentName {get; set;}
public String ActivityName {get; set;}
public int ActivityScore {get; set;} // out of 10 points
}
I currently have a List of "TrackActivity" called lstTrackScores, such that:
Barbara, juggling, 9
Barbara, cycling, 7
Chris, cycling, 9
Dennis, juggling, 8
Dennis, cycling, 6
Dennis, archery, 10
I don't know in advance how many unique students are in my List, but I do find out at run-time the maximum number of activities each student can participate in. How do I display the above information in a datagrid such that the number of unique students act as the number of rows (here, 3: Barbara, Chris, and Dennis), and the number of activities (here, 3: juggling, cycling, archery) act as the number of columns?
Then, in each cell, there would be a score if the student participated in that activity, and a blank if they did not participate in that activity. Ultimately, I'd like to display the above in a datagrid without having to change my class.
I tried to determine the number of unique students by doing this:
lstTrackScores.Select(x => x.StudentNames).Distinct().Count();
I think I want to create a 2-dimensional array with number of rows equal to the Count above, and number of columns equal to 3. Then, somehow, I display that array to a Datagrid, but I don't know how to do this. I'm using C# 2010 Express.