DevExpress TreeList 不显示子节点而是显示为根节点

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

我有 TreeList 读数来自 List(Of LedgerAccountEntry)()

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

表单加载中:

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

稍后:

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

这些只是相关部分。如果您需要更多信息,请告诉我。

结果是没有子节点的平面树,我检查了 ID 存在并且正在正确返回。

这是因为您正在使用 ParentLedgerAccountSys 作为字段。您需要将 ParentLedgerAccountSys 转换为 属性 或添加另一个 属性 代表您的 ParentLedgerAccountSys 字段。
这是示例:

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