Dynamically add columns to GridColumnModelList

May 15, 2012 at 4:02 PM

I need to store different configurations (profiles) of a particular grid and load them at runtime according to the logged in user.

I have a class ProfileColumn - a list of these are returned for the selected grid from the db and I then need to assign them to the GridColumnModelList - something like:

public  class ProfileColumn 
{      
	public int Id { get; set; }
	public string Caption { get; set; }
	public string Name { get; set; }
	public bool IsEditable { get; set; }
	public bool IsHidden { get; set; }
}  

public class GridProfile<T> where T : class    
{
	public GridColumnModelList<T> Columns { get; private set; }
	public int Id { get; set; }
	public string Name { get; set; }
	public int GridId { get; set; }

	public GridProfile() {}

	public GridProfile(int profileId)
	{
		Id = profileId;
		Columns = GetColumns();
	}

	protected GridColumnModelList<T> GetColumns()
	{
		var columns = new GridColumnModelList<T>();
		List<ProfileColumn> cols = GetProfileColumns(profileId);
		foreach (var profileColumn in cols)
		{
			var column = profileColumn;
			columns.Add(x => new GridColumnModel(column.Name)
				.SetHidden(column.IsHidden)
				.SetEditable(column.IsEditable)
				);
		}
		return columns;
	}
}


The GridColumnModelList is populated with the correct amount of columns but the properties are never set.

Is there a way to do this?

 

 

 

 

Coordinator
Jun 18, 2012 at 2:21 PM

Could you post the code building the Grid control?