-1

Say I have some Student class:

class Student {
   string Name { get; private set; }
   int[] Assignments { get; set; }
   char Grade { get { return Assignments.Sum() > 300 ? 'P' : 'F'; } }
}

where there is some known, constant, but impractically large number of assignments per student.

I'd like to represent the student's grades in a "Gradebook" app using a DataGrid, where there's a column for the students name, current pass/fail status, then the scores for each assignment, without creating a column for each assignment manually.

Is this possible?

Somkun
  • 99
  • 11
  • Yes, use ICustomTypeDescriptor and ITypedList interfaces. The DataGrid wants to display a rectangular grid of data and so when you have a class that does not naturally have a list of properties to display as columns you can use this interfaces to "flatten" the row. See my answer to this question: https://stackoverflow.com/questions/44958139/datagrid-with-dynamic-editable-columns/44981727#44981727 – AQuirky Mar 09 '18 at 02:30
  • yes, it is possible. do some research – ASh Mar 09 '18 at 09:23

1 Answers1

0

Can you add a Property AssignmentsStr and Binding to it?

 class Student {
       string Name { get; private set; }
       int[] Assignments { get; set; }
       char Grade { get { return Assignments.Sum() > 300 ? 'P' : 'F'; } }
       public string AssignmentsStr
       {get{return string.join(",",Assignments);}}
    }
zhaojingbo
  • 131
  • 6
  • This would technically work, but wouldn't allow the user to sort by a given assignment's grades, or edit them without a large amount of dev work (would have to split, reparse, throw errors for non-number results, ect) – Somkun Mar 09 '18 at 02:00
  • Do you want to add DataGridTextColumn binding to Assignments[0](Assignments[1],Assignments[2],etc) by code – zhaojingbo Mar 09 '18 at 05:48