Create Dynamic Columns and Dynamic Data Binding for WPF Datagrid or DevexGridcontrol

I have the following data structure:

public class StudentScore {
    public string ScoreValue{ get; set; }
}

public class Student {
    public string StudentName { get; set; }
    //Scores.Count will be = EndDate-StartDate
    public ObservableCollection<StudentScore> Scores { get;set; } 
}

ObservableCollection<Student> Students { get; set; }
public DateTime StartDate { get; set; } //Can be changed by user dynamically
public DateTime EndDate { get; set; } //Can be changed dynamically

      

What I'm curious to achieve in WPF DataGrid / DevExpress GridControl is like this: Column 1

it is always captured, it is the student's name, and the remaining columns will be count based only Scores

, and each row has to fill in the student's name and scores.

And each cell must have a two-way binding where the user can edit the score to reflect it in the actual VM property.

STudent poc image
I tried to set the property AutoGenerateColumns

to true - it only generates two columns because I only have properties StudentName

and Scores

. So I need something that can generate columns from the collection for each row.

+3


source to share


1 answer


You can link grid columns using the GridControl.ColumnsSource property .
See the following Help article for a detailed description of this approach: Binding to a Column Collection .



+1


source







All Articles