I have a list of StudentViewModel
object. I am binding this list with a DataGridView, and the column generatation is set to automatic according to the bound model's properties.
public async Task LoadGridView()
{
Tuple<List<StudentViewModel>, int> result = await App.StudentService.SearchAsync(studentRequestModel);
dataGridView1.DataSource = null;
dataGridView1.DataSource = result.Item1;
}
In the StudentViewModel, I have decorated some of the properties with a custom attribute IsViewable
.
[AttributeUsage(AttributeTargets.Property)]
public class IsViewable: Attribute
{
public bool Value { get; set; }
}
usage:
[IsViewable(Value = true)]
public string Name { get; set; }
Idea is, just before binding with the UI Control, I want to filter the list and make a new list of anonymous object so that my grid will be populated with only selected properties.
Note: I don't want to create separate view models specific to Grids. I will refactor it if it creates performance issues.
Aucun commentaire:
Enregistrer un commentaire