Click here to Skip to main content
15,890,897 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionFill Treeview using recursion Pin
sterenas7-Dec-18 10:15
sterenas7-Dec-18 10:15 
AnswerRe: Fill Treeview using recursion Pin
Eddy Vluggen8-Dec-18 0:12
professionalEddy Vluggen8-Dec-18 0:12 
AnswerRe: Fill Treeview using recursion Pin
Eddy Vluggen8-Dec-18 1:46
professionalEddy Vluggen8-Dec-18 1:46 
GeneralRe: Fill Treeview using recursion Pin
sterenas8-Dec-18 4:26
sterenas8-Dec-18 4:26 
GeneralRe: Fill Treeview using recursion Pin
Eddy Vluggen8-Dec-18 4:37
professionalEddy Vluggen8-Dec-18 4:37 
GeneralRe: Fill Treeview using recursion Pin
sterenas10-Dec-18 3:52
sterenas10-Dec-18 3:52 
GeneralRe: Fill Treeview using recursion Pin
Eddy Vluggen11-Dec-18 2:08
professionalEddy Vluggen11-Dec-18 2:08 
GeneralRe: Fill Treeview using recursion Pin
sterenas11-Dec-18 5:34
sterenas11-Dec-18 5:34 
Hey Eddie,
You actually didn't add another level to the data. I have 4 elements:
VB
New Thingy("SHOP 1", 55, "Large", 52)


We're pretty close with the code below but there must be something wrong with the statement after the only ELSE. I'm getting:
VB
Shops
---Shop1
------Uncategorized
------Animals
------Plants
...
---Shop2
------Uncategorized
------Animals
------Plants
...

ie it's not taking into account the parent categories to show them right.  About to give up on this treeview and use a datagridview which is far simpler to understand :(


VB
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       Dim data As List(Of Thingy) = New List(Of Thingy) From {
           New Thingy("SHOP 1", 15, "Uncategorized", 0),
           New Thingy("SHOP 1", 50, "Animals", 0),
           New Thingy("SHOP 1", 51, "Plants", 0),
           New Thingy("SHOP 1", 52, "Dogs", 50),
           New Thingy("SHOP 1", 53, "Small", 52),
           New Thingy("SHOP 1", 54, "Medium", 52),
           New Thingy("SHOP 1", 55, "Large", 52),
           New Thingy("SHOP 1", 56, "Trees", 51),
           New Thingy("SHOP 1", 57, "Flowers", 51),
           New Thingy("SHOP 1", 58, "White", 55),
           New Thingy("SHOP 1", 59, "Brown", 55),
           New Thingy("SHOP 2", 15, "Uncategorized", 0),
           New Thingy("SHOP 2", 50, "Animals", 0),
           New Thingy("SHOP 2", 51, "Plants", 0),
           New Thingy("SHOP 2", 52, "Dogs", 50),
           New Thingy("SHOP 2", 53, "Small", 52),
           New Thingy("SHOP 2", 54, "Medium", 52),
           New Thingy("SHOP 2", 55, "Large", 52),
           New Thingy("SHOP 2", 56, "Trees", 51),
           New Thingy("SHOP 2", 57, "Flowers", 51),
           New Thingy("SHOP 2", 58, "White", 55),
           New Thingy("SHOP 2", 59, "Brown", 55)
       }

       ' Add all shops to the tree
       tv.Nodes.Add("Shops", "Shops")

       For Each item As Thingy In data
           Dim possibleRoot As TreeNode() = tv.Nodes.Find(item.ShopName, searchAllChildren:=True)
           If possibleRoot.Count = 0 Then
               tv.Nodes(0).Nodes.Add(key:=item.ShopName, text:=item.ShopName)
           End If
       Next

       For Each item As Thingy In data
           Dim possibleParent As TreeNode() = tv.Nodes.Find(item.ShopName, searchAllChildren:=True)
           If possibleParent.Count = 0 Then
               ' It'll never go this way as I've added all the shops ahead of time
               tv.Nodes.Add(key:=item.IdCategory, text:=item.CategoryName)
           Else
               possibleParent.First().Nodes.Add(key:=item.IdCategory, text:=item.CategoryName)
           End If
       Next
       tv.ExpandAll()
   End Sub



And the class is now:
VB
Public Class Thingy
    Sub New(ShpName As String, id As Long, catName As String, parentId As Long)
        ShopName = ShpName
        IdCategory = id
        CategoryName = catName
        ParentCategory = parentId
    End Sub
    Public Property ShopName As String
    Public Property IdCategory As Long
    Public Property CategoryName As String
    Public Property ParentCategory As Long

End Class


Ik zit vast met deze boom. Heel erg bedankt voor al je hulp Smile | :)
Sergio
GeneralRe: Fill Treeview using recursion Pin
Eddy Vluggen11-Dec-18 6:16
professionalEddy Vluggen11-Dec-18 6:16 
GeneralRe: Fill Treeview using recursion Pin
sterenas11-Dec-18 7:51
sterenas11-Dec-18 7:51 
GeneralRe: Fill Treeview using recursion Pin
Eddy Vluggen11-Dec-18 23:10
professionalEddy Vluggen11-Dec-18 23:10 
Questionentity framework Group by multiple columns and count the number of groups with more than 1 item Pin
desanti6-Dec-18 11:24
desanti6-Dec-18 11:24 
AnswerRe: entity framework Group by multiple columns and count the number of groups with more than 1 item Pin
Richard Deeming7-Dec-18 7:46
mveRichard Deeming7-Dec-18 7:46 
QuestionProblems with Entity Famework and bindingsources Pin
desanti6-Dec-18 0:13
desanti6-Dec-18 0:13 
QuestionDrawlines is correct or not ? Pin
Coffee_Break5-Dec-18 1:27
Coffee_Break5-Dec-18 1:27 
AnswerRe: Drawlines is correct or not ? Pin
Eddy Vluggen5-Dec-18 2:05
professionalEddy Vluggen5-Dec-18 2:05 
Questionsave my excel invoice in excel sheet Pin
kami1244-Dec-18 8:04
kami1244-Dec-18 8:04 
QuestionRe: save my excel invoice in excel sheet Pin
Richard MacCutchan4-Dec-18 8:58
mveRichard MacCutchan4-Dec-18 8:58 
QuestionError ContextSwitchDeadlock Pin
desanti4-Dec-18 5:33
desanti4-Dec-18 5:33 
AnswerRe: Error ContextSwitchDeadlock Pin
Eddy Vluggen4-Dec-18 6:33
professionalEddy Vluggen4-Dec-18 6:33 
GeneralRe: Error ContextSwitchDeadlock Pin
desanti4-Dec-18 8:45
desanti4-Dec-18 8:45 
GeneralRe: Error ContextSwitchDeadlock Pin
Eddy Vluggen4-Dec-18 9:37
professionalEddy Vluggen4-Dec-18 9:37 
GeneralRe: Error ContextSwitchDeadlock Pin
desanti5-Dec-18 1:18
desanti5-Dec-18 1:18 
GeneralRe: Error ContextSwitchDeadlock Pin
Eddy Vluggen5-Dec-18 1:43
professionalEddy Vluggen5-Dec-18 1:43 
GeneralRe: Error ContextSwitchDeadlock Pin
desanti5-Dec-18 2:08
desanti5-Dec-18 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.