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
110
Nested Objects with Same Columns
posted

I have an object with a list of that object on it.  I am trying to use the Nested ability of the grid.  The problem is there are properties on the Object that I do not want shown, so I cannot use AutoGenerateFields.  Since I, theoretically, could have infinite levels of sub, how do I define the fields??

Example Object

Public Class Person

Private _Name As String
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal value As String)
_Name = value
End Set
End Property

Private _Age As Integer
Public Property Age() As Integer
Get
Return _Age
End Get
Set(ByVal value As Integer)
_Age = value
End Set
End Property

Private _Kids As List(Of Person)
Public Property Kids() As List(Of Person)
Get
If _Kids Is Nothing Then _Kids = New List(Of Person)
Return _Kids
End Get
Set(ByVal value As List(Of Person))
_Kids = value
End Set
End Property

'\\\\\\\\\\\ Property I Do Not Want in the grid \\\\\\\\\\
Private _Married As Boolean
Public Property Married() As Boolean
Get
Return _Married
End Get
Set(ByVal value As Boolean)
_Married = value
End Set
End Property

End Class

Also how can I prevent the grid from showing the expand button when the Kids Collection is empty??

Thank you

Parents
No Data
Reply
  • 34810
    Offline posted

    Hello Bryan,

    As mentioned in a support case that we have together, in order to prevent the grid from showing the expansion indicator when the Kids collection is empty, I would recommend setting the XamDataGrid.FieldLayoutSettings.ExpansionIndicatorDisplayMode property to "CheckOnDisplay." This will check the child collection for child records, and only display the indicator if children exist.

    As far as defining the Fields for your recursive structure, you only really need a single FieldLayout for this, but I would recommend setting the XamDataGrid.FieldLayoutSettings.AutoGenerateFields property to "False" first, as this will tell the grid that you wish to manually generate columns and not auto-generate fields for every property on your underlying data item. At this point, you can add a Field with a Name pointing at your underlying property. Since the FieldLayouts of the XamDataGrid are created on a per-data-type basis, you can simply add an extra Field for the "Kids" collection and the FieldLayout will recursively loop through any children in your current structure.

    I have attached a sample project to demonstrate the above. I hope this helps you.

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

    Sincerely,
    Andrew
    Associate Developer

    XDGRecursiveDataStructureDemo.zip
Children
No Data