Hi
I have a requirement where i need to generate some columns of a grid dynamically at runtime. I have found a solution you have provided as part of another ticket and I updated the code to see if it works for my situation. In my case i need to show checkboxes and allow the user to edit it.
I am attaching the modified source code.
ICollection<
EmployeeRecord
> employeeRecords;
// Get some mock data
employeeRecords = GetDummyData();
GridViewDataColumn tempDataColumn = new GridViewDataColumn();
//Add the known columns
tempDataColumn=new GridViewDataColumn()
{
UniqueName = "EmployeeName"
, DataMemberBinding = new Binding("EmployeeName")
};
tempDataColumn.IsReadOnly = true;
this.grid.Columns.Add(tempDataColumn);
tempDataColumn = new GridViewDataColumn()
{
UniqueName = "ID"
,
DataMemberBinding = new Binding("ID")
};
tempDataColumn.IsReadOnly = true;
this.grid.Columns.Add(tempDataColumn);
// Now add the dynamic number of columns
// Determines the maximum number of months that any employee has worked.
int maxNumberOfMonths = employeeRecords.Max((x) => x.RolePermission.Count);
for (int i = 0; i < maxNumberOfMonths; i++)
{
tempDataColumn=new GridViewDataColumn()
{
UniqueName = "Read" + (i + 1)
, DataMemberBinding = new Binding("RolePermission[" + i + "]")
, DataType = typeof(bool)
};
tempDataColumn.EditorSettings=new CheckBoxEditorSettings();
tempDataColumn.IsReadOnly = false;
this.grid.Columns.Add(tempDataColumn);
}
// Finally, bind the grid
this.grid.ItemsSource = employeeRecords;
I have to solve following problems
1. I am able to uncheck the check boxes but it is getting reset when I move to next row i need this persisted so that I can save those values to the database.
2. I need to hide checkboxes for some rows under some columns based on a value is it possible directly something i can set while creating the columns.
Thanks & Regards
Kiran