|
-
Oct 16th, 2011, 11:43 AM
#1
Thread Starter
Frenzied Member
same items in different places in tree
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
Code:
Main Category
Category
Sub category
Recipe
Recipe
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.
The database layout is as such
Code:
counter Routine Descr Snip ParentID Subcat
counter is an auto-incremented field.
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
-
Oct 17th, 2011, 07:50 PM
#2
Thread Starter
Frenzied Member
Re: same items in different places in tree
Would like to find out why. Tried a few different was of loading the tree, all turned out the same. Does anybody have an idea or a better way of loading the tree? Is the function process at least in the right direction?
-
Oct 20th, 2011, 08:32 PM
#3
Thread Starter
Frenzied Member
Re: same items in different places in tree
sorry to bring this back, but I would love to find the cause and get it fixed.
-
Oct 26th, 2011, 09:08 AM
#4
Thread Starter
Frenzied Member
Re: same items in different places in tree
is there a better way to load the tree? It all started once I put them in children of the parent
-
Nov 4th, 2011, 03:19 PM
#5
Thread Starter
Frenzied Member
Re: same items in different places in tree
Please guys, doesn't anybody have any idea?
-
Nov 8th, 2011, 09:26 PM
#6
Thread Starter
Frenzied Member
Re: same items in different places in tree
seems I stumped the pros lol
did I not explain myself very well?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|