Hello,
I have a multilevel hierarchical XamDataGrid. I wan to Indent parent and child in only first column of every child record.
For this, I tried to apply CellValuePresenter style to first column of child record's FieldLayout with Left Margin 20.
It works fine for first child record but for second child level onwards also it applies margin 20 to first field.
Whereas for second child now left margin should be 40 and third level child should have left margin of 60 and so on.
I thought of achieving this by applying cellvaluepresenter to every field layout from code behind by multiplying left margin by nesting depth of current record or by adding 20 to parent record's margin. Is this possible?
How do I achieve this? or is there any work around. Other solutions are not working as expected for me.
Thanks,
Priya
Hello Priya,
From your description, I am gathering that you want to indent the child rows further and further with each hierarchical level.
To do this, I would not recommend doing anything with the CellValuePresenter, but rather the DataRecordPresenter. To do this without having to write any Styles, I would recommend handling the XamDataGrid’s Loaded event and use a for-loop to loop from 0 to MyXamDataGrid.FieldLayouts.Count. In this loop, you can get the FieldLayout and create a Style for DataRecordPresenter that sets the Margin property. Then, set the style on the FieldLayout using MyFieldLayout.Settings.DataRecordPresenterStyle = myStyle.
Alternatively, consider the method demonstrated here: http://stackoverflow.com/questions/5514093/xamdatagrid-indenting-nested-levels.
Please note that these methods require you to define your hierarchical levels manually.
I have attached a sample application demonstrating the Loaded event recommendation.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewDeveloper Support Engineer IInfragistics Inc.www.infragistics.com/support
Hello Andrew,
Thank you for quick reply.
But I have nested collection as my XamDataGrid data-source with 2 field layouts for parent & children each.
Is there any way to dynamically calculate left margin based on nesting depth of record?
In the XamDataGrid.FieldLayoutSettings, there is a property named AutoFitMode. If you set this to ExtendLastField, I believe you will re-align the columns properly.
Thank you for quick reply. I tried that. In that case it gives below layout:
Another option to use the aligned child fields with AutoFit = True is to use the OnlyWithVisibleStarFields option of the AutoFitMode. This mode will look for any Fields within a FieldLayout and AutoFit them based on whether their Width has a * extent or not. Below is a link to our online documentation that may provide a better description of the OnlyWithVisibleStarFields AutoFitMode.
Link: http://help.infragistics.com/Help/Doc/WPF/2012.1/CLR4.0/html/InfragisticsWPF4.DataPresenter.v12.1~Infragistics.Windows.DataPresenter.AutoFitMode.html.
I have also attached an updated sample application that uses this AutoFitMode to demonstrate.
Hey Andrew,
This sample is not working as expected on my machine. Below is the screenshot:
I have spoken to our development team on this issue about a possible resolution, and have since received a response from them. The XamDataGrid is not really set up to handle column alignment when using AutoFit. Awhile back, there was a product idea posted by another one of our community members for a XamDataTree XamDataGrid hybrid so that this alignment could be made easier. That idea has been approved and our development teams are working on it now. Below is the link to the discussion about this idea.
Link: http://ideas.infragistics.com/forums/192363-wpf/suggestions/5988260-new-wpf-tree-grid-control#comments
Just checking in, did you have any other questions or concerns on this matter?