vb.netwinformsdevexpresstreelistxtratreelist

DevExpress TreeList not displaying child nodes and displaying as root nodes instead


I have a TreeList reading from a List(Of LedgerAccountEntry)().

Public Class LedgerAccountEntry
    Public Property LedgerAccountSys() As Integer 
    Public ParentLedgerAccountSys As Integer
    '
    '
    ' ETC
End Class

In form load:

tlLedgerAccounts.ParentFieldName = "ParentLedgerAccountSys"
tlLedgerAccounts.KeyFieldName = "LedgerAccountSys"
tlLedgerAccounts.RootValue = -1

Later on:

While bla
    entry.LedgerAccountSys = rstAccounts("LedgerAccountSys").Value
    entry.ParentLedgerAccountSys = IIf(rstAccounts("ParentLedgerAccountSys").Value Is DBNull.Value, -1, rstAccounts("ParentLedgerAccountSys").Value)
    lst.add(entry)
End While            
tlLedgerAccounts.DataSource = lst

These are just the relevant parts. Please let me know if you need more info.

The result is flat tree with no child nodes, I checked that the IDs exists and are being returned correctly.


Solution

  • This is because you are using ParentLedgerAccountSys as field. You need to convert your ParentLedgerAccountSys to property or add another property which represents your ParentLedgerAccountSys field.
    Here is example:

    Public Class LedgerAccountEntry
        Public Property LedgerAccountSys As Integer
        'Public ParentLedgerAccountSys As Integer <-- Here is field.
        Public Property ParentLedgerAccountSys As Integer '<-- Here is property instead of field.
        '
        '
        ' ETC
    End Class