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
120
XamDataGrid - How to hide/disable add new row on selected levels in hierarchy
posted

Hello

I have a grid with a DataSet containing two or more tables related with DataRelations. When I add AllowAddNew="True" to FieldLayoutSettings, the add new row functionality is available on all levels of the grid. Is it possible to hide or disable the functionality on selected levels? For instance we don't want users to add anything to the top level.

Regards

Marek

Parents
  • 34430
    Verified Answer
    Offline posted

    Hello Marek,

    Thank you for your post.

    I am under the impression that you are currently adding the AllowAddNew setting to the XamDataGrid.FieldLayoutSettings property. When doing this, it sets it globally for the entirety of the XamDataGrid, but there are ways that you can prevent this from happening on certain levels.

    My recommendation for this really depends on whether or not you are manually generating your FieldLayout elements in the XamDataGrid for your hierarchy. If you are manually generating them, then I would recommend setting the FieldLayout.Settings.AllowAddNew property for your parent and child levels to prevent the add new record on the parent level, but allow it on a child level. The code to do this could look something like the following:

    <ig:XamDataGrid.FieldLayouts>
    <ig:FieldLayout>
    <ig:FieldLayout.Settings>
    <ig:FieldLayoutSettings AllowAddNew="True"/>

    If you are auto-generating your fields and field layouts in the XamDataGrid, then I would recommend hooking into the FieldLayoutInitialized event of the XamDataGrid. This will fire as each FieldLayout in the grid is initialized, which, in the case of the parent FieldLayout, happens when the XamDataGrid is loaded. For the child ones, this happens when an expandable parent record becomes expanded and the child records are shown. When this event fires, you can get the corresponding FieldLayout from the e.FieldLayout property, where e is the event arguments of the event handler. At this point, you can set the following:

    e.FieldLayout.Settings.AllowAddNew = myAddNewValue;

    One last thing to note about the FieldLayoutInitialized route. To find out which FieldLayout is which, you can reference the e.FieldLayout.ParentFieldLayout property. This will be null for the parent one, as it will return the FieldLayout in the nested level above the currently initializing one.

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

    Sincerely,
    Andrew
    Associate Developer

Reply Children