Hi,
I was wondering if it would be possible to change the columns displayed in a XamDataGrid based on a List of strings, being the names of the columns, using databinding only?
An example of the situation might be that I have a grid bound to a List of Person objects. The Person object has four properties, FirstName, LastName, Age, Height, Gender. Now I'd like somehow to bind this to a list of strings in my viewmodel, say "FirstName","LastName" and then have this display only the FirstName and LastName columns.
This would be easy enough to do in code as you could loop through the columns and set the ones you don't want to see to be collapsed or hidden, but I was trying to avoid that if at all possible....??
Thanks,
Al
Hello,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
I have been looking into your requirement and I can suggest you use the XamDataGrid’s Save/Load Customization feature. Here it is described how to do so:
http://help.infragistics.com/Help/NetAdvantage/WPF/2011.2/CLR4.0/html/xamDataPresenter_Save_Field_Customizations.html
http://help.infragistics.com/NetAdvantage/WPF/2011.2/CLR4.0/?page=xamDataPresenter_Load_Field_Customizations.html
using this, you can save the FieldLayout to an XML file for every user and then load it . Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Sorry I was simplifying by saying I needed another control. What is actually happening is that I'm getting a user's profile from the database. In this profile will be a list of strings, which correspond to the columns he wants to see on the grid. So he wouldn't be opening up a fieldchooser to select them manually.
I have been looking into your requirement and I can say that the thing you want to achieve is already a built-in functionality of the XamDataGrid. The thing you need is the FieldChooser, here you can see an overview of it:
http://help.infragistics.com/NetAdvantage/WPF/2011.2/CLR4.0/?page=xamDataPresenter_About_the_Field_Chooser.html
Please let me know if this helps you or you need further clarifications on this matter.
Hi Stefan,
Thanks for your response. Unfortunately it's not quite what I'm after. This enables you to define the fields before running the program, ie at compile time. I'd like to change them dynamically at run time.
An example:
I have two components, one has a grid, the other has a list of checkboxes.
The grid in the first component has three columns, A, B and C.
The second component has three checkboxes, A, B and C. When one of these checkboxes is clicked an event is raised and picked up by the first component (in its VM).
I would like the columns to be hidden/visible depending on whether these checkboxes are checked. The question is - can this be done via binding or does it have to be done programmatically? i.e. Can I have a list of visible column names that binds to something in the XamDataGrid and will dynamically hide/show the columns, or do I have to loop around the columns programmatically and hide/show them depending whether they are in that list?