I made a small recipe program and all seems to work fine. Except I seem to see some carry over or bleed over in some recipes. The layout is as follows
Recipe can be in Category and a Sub Category. That all seems to work great when you view the attachment "Appertizers". But when you go to the last Category you also see them there as well. Which they shouldn't be. The database is access and everything is correct in there, the recipes in the sub cat are right where they should be.Code:Main Category Category Sub category Recipe Recipe
The database layout is as such
counter is an auto-incremented field.Code:counter Routine Descr Snip ParentID Subcat
ParentId is 0 for all categories. But if a subcat is set to 1 then ParentID is not 0 but the counter id. Same for recipes, Parent ID is the counter number.
The below code is what I use to populate the tree. It all looks good but like I said, I have bleed over for all recipes that are in subcats only. Make sense? I just need to see how to fix the carry over for the items in the last category. Seen in the vegetables attachment.
Code:Public Sub LoadTreeView(ByVal parentNode As TreeNode) 'My.Computer.FileSystem.CurrentDirectory Dim x As Integer Dim PNode As TreeNode Try If connection.State = ConnectionState.Closed Then connection.Open() End If Me.adapter.Fill(Me.table) ' Create a DataView with the table. Dim view As New DataView(Me.table) PNode = Nothing x = 0 Dim i As Integer For i = 0 To view.Count - 1 ' MsgBox(view(i)("ParentID")) If CInt(view(i)("ParentID").ToString) = 0 Then PNode = parentNode.Nodes.Add(view(i)("counter").ToString, view(i)("Routine").ToString, 3, 4) PNode.Tag = view(i)("counter").ToString PNode.Name = view(i)("Routine").ToString End If Dim childqueryString As String = "ParentID= " & view(i)("counter").ToString Dim dr = table.Select(childqueryString).Length Dim Cnode As TreeNode If Not dr = 0 Then Dim Childview As DataView = New DataView(table) With Childview .RowFilter = "ParentID= " & view(i)("counter").ToString .Sort = "Subcat DESC, Routine ASC" End With For d = 0 To Childview.Count - 1 ' adds routines under correct folder If CInt(Childview(d)("ParentID").ToString) > 0 And Not PNode Is Nothing Then 'MsgBox(Childview(d)("Routine").ToString & "/ Counter=" & Childview(d)("Counter").ToString & "\ Recipe" & Childview(d)("Routine").ToString & "Sub" & Childview(d)("SubCat").ToString) If CInt(Childview(d)("SubCat").ToString) = 1 Then ' it is a subcategory so we need the folder image added Cnode = PNode.Nodes.Add(Childview(d)("counter").ToString, Childview(d)("Routine").ToString, 3, 4) Cnode.Tag = Childview(d)("counter") Cnode.Name = Childview(d)("Routine").ToString 'we find all repices for subcategory Dim Cnode2 As TreeNode Dim SubChildview As DataView = New DataView(table) With SubChildview .RowFilter = "ParentID= " & Childview(d)("counter").ToString .Sort = "Routine ASC" End With For e = 0 To SubChildview.Count - 1 If CInt(SubChildview(e)("ParentID").ToString) > 0 And Not Cnode Is Nothing Then Cnode2 = Cnode.Nodes.Add(SubChildview(e)("counter").ToString, SubChildview(e)("Routine").ToString, 1, 2) Cnode2.Tag = SubChildview(e)("counter") Cnode2.Name = SubChildview(e)("Routine").ToString 'x = x + 1 End If Next e Else Cnode = PNode.Nodes.Add(Childview(d)("counter").ToString, Childview(d)("Routine").ToString, 1, 2) Cnode.Tag = Childview(d)("counter") Cnode.Name = Childview(d)("Routine").ToString x = x + 1 End If End If Next d End If TSStatusLblCounter.Text = "Total Recipes - " & x Next i Catch ex As Exception MsgBox("Failed to load Tree" & Chr(13) & Chr(13) & ex.Message, vbOKOnly, "Failed To Load") Debug.WriteLine(ex.Message) End Try End Sub




Reply With Quote