Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
Using multiple field layouts in XamTreeGrid
posted

Hi,

I have a custom XamTreeGrid which represents a tree structure and it has multiple fields inside it. The control is to be used in different different places. For this purpose I have defined different FieldLayout in a resource dictionary as the control may have additional fields to show in some other areas. If every time I clear the FieldLayouts and add a layout, I get the following exception 

System.InvalidOperationException
HResult=0x80131509
Message=FieldLayout can not be moved to another DataPresenterBase.
Source=InfragisticsWPF.DataPresenter

My questions are following

  1. How can we load/unload FieldLayout in FieldLayouts at run time? I saw on some other threads to use SaveCustomizations and LoadCustomizations but my concern is, out of N number of field layouts, how would that help me to choose a specific layout?
  2. Let say I have N number of FieldLayout defined in resource dictionary, how can I add those layouts to XamTreeGrid in XAML(Not using code) using resource key?

Let me know if there is a solution available for these 2 questions.

Parents
No Data
Reply
  • 34430
    Offline posted

    Hello Yasir,

    I have been investigating into the behavior you are seeing, and this behavior generally happens when you try to add the same instance of a FieldLayout to multiple instances of a DataPresenterBase such as the XamTreeGrid or XamDataGrid. The FieldLayout is essentially "owned" by the XamTreeGrid that it is placed in and the same instance cannot exist in multiple grids. Regarding your questions…

    1. The SaveCustomizations and LoadCustomizations methods are not used for saving and loading the actual FieldLayouts themselves – they are used for saving and loading the customizations on those FieldLayouts. Essentially, if you try to load the customizations, the grid will look for a FieldLayout in its FieldLayouts collection that matches all of the Fields that existed when the customizations were saved and then load the customizations (field size, sort status, filtering status, etc.) to it.

    As for your actual question, the best way to add FieldLayouts to the XamTreeGrid at runtime is to do it in code and add to the FieldLayouts collection of the grid.

    2. It is not possible to add FieldLayouts by a resource key purely in XAML as the FieldLayouts collection on the XamTreeGrid is read-only. That is, the collection itself is so you can add elements to it, but you cannot replace the collection itself. You would need to get the FieldLayout using its resource key in code and then add it.

    Please let me know if you have any other questions or concerns on this matter.

Children
No Data