The OneStream Community is temporarily frozen until June 29th due to the ongoing maintenance. Please read the blog post here to learn more.
Forum Discussion
FlorisvdPoel
2 years agoContributor
Tree view showing full hierarchy
Hi everyone,
Thanks in advance for helping.
I am new to tree views and trying to get a simple hierarchy (from the account dimension) to show as a tree view. Part of the structure is shown in the ...
- 2 years ago
I like to use https://en.wikipedia.org/wiki/Recursive_function for things like this. Not sure if there is a more out of the box way as I haven't done a lot with treeviews.
I asked AI to turn your code into a recursive function. No idea if it works but it might set you on the path.
Sub BuildTree(ByVal si As SessionInfo, ByVal DimPk As DimPk, ByVal parentMbrId As Integer, ByVal parentMbrName As String, ByVal parentMbrDescription As String, ByVal textColour As String, ByVal imageSource As String, ByVal imageName As String, ByVal isBold As Boolean, ByVal isEnabled As Boolean, ByVal isSelected As Boolean, ByVal isExpanded As Boolean, ByVal treeCollection As XFTreeItemCollection) 'Declare the child list of the parent Dim childList As List(Of Member) = BRApi.Finance.Members.GetChildren(si, DimPk, parentMbrId) 'Dim the new XFTreeItem List Dim treeChildren As New List(Of XFTreeItem)() 'Loop through the children For Each child As Member In childList ' Recursively build children of children Dim childTreeCollection As New XFTreeItemCollection() BuildTree(si, DimPk, child.Id, child.Name, child.NameAndDescription, textColour, imageSource, imageName, isBold, isEnabled, isSelected, isExpanded, childTreeCollection) ' Create XFTreeItem for current child and add children to it Dim childTreeItem As New XFTreeItem(child.Name, child.NameAndDescription, textColour, isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, child.Name, childTreeCollection) treeChildren.Add(childTreeItem) Next ' Add the children to the parent Dim parentTreeItem As New XFTreeItem(parentMbrName, parentMbrDescription, textColour, isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, parentMbrName, treeChildren) treeCollection.TreeItems.Add(parentTreeItem) End Sub ' Usage: Dim DimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "actAccount") Dim parentMbrId As Integer = BRApi.Finance.Members.GetMemberId(si, dimTypeId.Account, "CF_000000") Dim parentMbr As Member = BRApi.Finance.Members.GetMember(si, dimTypeId.Account, parentMbrId) Dim textColour As String = XFColors.Black.Name Dim imageSource As String = XFImageFileSourceType.ClientImage Dim imageName As String = XFClientImageTypes.StatusGrayBall.Name Dim isBold As Boolean = False Dim isEnabled As Boolean = True Dim isSelected As Boolean = False Dim isExpanded As Boolean = True Dim treeCollection As New XFTreeItemCollection() BuildTree(si, DimPk, parentMbrId, parentMbr.Name, parentMbr.NameAndDescription, textColour, imageSource, imageName, isBold, isEnabled, isSelected, isExpanded, treeCollection)
DanielWillis
2 years agoValued Contributor
I like to use https://en.wikipedia.org/wiki/Recursive_function for things like this. Not sure if there is a more out of the box way as I haven't done a lot with treeviews.
I asked AI to turn your code into a recursive function. No idea if it works but it might set you on the path.
Sub BuildTree(ByVal si As SessionInfo, ByVal DimPk As DimPk, ByVal parentMbrId As Integer, ByVal parentMbrName As String, ByVal parentMbrDescription As String, ByVal textColour As String, ByVal imageSource As String, ByVal imageName As String, ByVal isBold As Boolean, ByVal isEnabled As Boolean, ByVal isSelected As Boolean, ByVal isExpanded As Boolean, ByVal treeCollection As XFTreeItemCollection)
'Declare the child list of the parent
Dim childList As List(Of Member) = BRApi.Finance.Members.GetChildren(si, DimPk, parentMbrId)
'Dim the new XFTreeItem List
Dim treeChildren As New List(Of XFTreeItem)()
'Loop through the children
For Each child As Member In childList
' Recursively build children of children
Dim childTreeCollection As New XFTreeItemCollection()
BuildTree(si, DimPk, child.Id, child.Name, child.NameAndDescription, textColour, imageSource, imageName, isBold, isEnabled, isSelected, isExpanded, childTreeCollection)
' Create XFTreeItem for current child and add children to it
Dim childTreeItem As New XFTreeItem(child.Name, child.NameAndDescription, textColour, isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, child.Name, childTreeCollection)
treeChildren.Add(childTreeItem)
Next
' Add the children to the parent
Dim parentTreeItem As New XFTreeItem(parentMbrName, parentMbrDescription, textColour, isBold, isEnabled, isSelected, isExpanded, imageSource, imageName, parentMbrName, treeChildren)
treeCollection.TreeItems.Add(parentTreeItem)
End Sub
' Usage:
Dim DimPk As DimPk = BRApi.Finance.Dim.GetDimPk(si, "actAccount")
Dim parentMbrId As Integer = BRApi.Finance.Members.GetMemberId(si, dimTypeId.Account, "CF_000000")
Dim parentMbr As Member = BRApi.Finance.Members.GetMember(si, dimTypeId.Account, parentMbrId)
Dim textColour As String = XFColors.Black.Name
Dim imageSource As String = XFImageFileSourceType.ClientImage
Dim imageName As String = XFClientImageTypes.StatusGrayBall.Name
Dim isBold As Boolean = False
Dim isEnabled As Boolean = True
Dim isSelected As Boolean = False
Dim isExpanded As Boolean = True
Dim treeCollection As New XFTreeItemCollection()
BuildTree(si, DimPk, parentMbrId, parentMbr.Name, parentMbr.NameAndDescription, textColour, imageSource, imageName, isBold, isEnabled, isSelected, isExpanded, treeCollection)
Related Content
- 2 years ago
- 2 years ago
- 3 years ago