Question

Can a DataGrid dynamically mask the columns to be displayed?

Current Setup

DataGrid <--Binding--> Collection<Customer>

  1. The type Customer has about 100 different fields defined.
  2. Different views need to display different sets of columns (about 20 out of 100), chosen somehow dynamically, of the same Collection<Customer>.

Is there an option to dynamically mask the fields that will be displayed as columns in the DataGrid? Ideally, I want to use Infragistics' xamDataGrid, but any solution for a DataGrid will be a good starting point.


There are other similar questions out there, but they deal with either column filtering or variable number of rows.

Was it helpful?

Solution

If you are defining different views in code you could create different FieldLayouts and use the FieldLayout for the view that is needed. This would require setting the FieldLayout to be used in code by adding the layout to be used to the FieldLayouts collection.

If you are allowing the end user to define what is in the view, then you will likely want to define all possible fields and then allow the fields to be hidden or shown with the Field Chooser.

There are methods for saving and loading customizations to the fields that you can use to persist the layouts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top