MissouriTiger
Programmer
Hello out there in Tek-Land,
I'm hoping that someone can point out what I cannot see myself.
I have a node at the top of my tree, which is appearing twice, and no matter what I do, I cannot make it go away.
What is even stranger, the second instance of it appears to have an unknown character appended to the beginning of the text. At least that's how it appears in the tree. It shows up as a single black rectangle. But the text file my program reads form to populate the tree doesn't contain any extra characters as far as I can see. It is delimited with VbCrlf, but I split it into an array on VbCrlf.
Is it my code, or is it the source file?
Please see my code below. Note that the source file is split into an collection of strings. First the text file is split by VbCrlf (each row is a record). These strings are then split again, and the resulting strings are held in a collection.
Any help will be much appreciated.
----------
Tree Code
----------
Public Sub fillNav(ByVal productPaths As String)
Kiosk.Main.tvMainNav.Nodes.Clear()
' Break the string containing the paths up into array, one cell per product/path.
Dim arrPaths As Array = productPaths.Split(vbCrLf)
'Split by delimiter
Dim pathColl As New Collection, currentProduct As New Product
' Break the individual path strings up into an array, one cell per
' path level. Add them to a collection.
For Each strg As String In arrPaths
pathColl.Add(strg.Split(":"))
Next
'***************************************************
'EXAMPLE OF A PATH:
'
'Designs:Individual:Birds & Butterflies:ADC-801:Butterfly
'****************************************************
Dim arrCurrentPath As Array, pathNum As Integer
'Array and boolean flag to keep track of Top level group nodes.
Dim arrRootNodes() As String = New String() {}
ReDim arrRootNodes(50)
Dim nodeExists, rootNodeExists As Boolean, rootNum, i As Integer
nodeExists = False
rootNodeExists = False
rootNum = 0
rootNodeExists = False
'################ BUILD THE TREE ################
Dim currentNode As TreeNode() = Main.tvMainNav.Nodes.Find("", False)
Dim currentLevel As Integer, nodeID, nodeText, nodeTag As String, addNode As Boolean
nodeID = ""
nodeText = ""
nodeTag = ""
addNode = False
'Loop through the collection of paths, one path at a time.
For pathNum = 1 To pathColl.Count - 1 '?? Why -1? Weird.
arrCurrentPath = pathColl(pathNum)
' Stop before the last index. The last 2 indexes are a pair.
' The first is the 'name' of the product node. The second (last) is the text displayed by that node.
For currentLevel = 0 To (UBound(arrCurrentPath) - 1)
' Index 0 is the top node of the tree.
' There can be more than one top node.
addNode = False
nodeID = Trim(arrCurrentPath(currentLevel))
If currentLevel = 0 Then
rootNodeExists = False
'Check if this node has already been created.
For i = 0 To UBound(arrRootNodes)
If arrRootNodes(i) = nodeID Then
rootNodeExists = True
Exit For
End If
Next
If Not rootNodeExists Then
'Node not found. Create the new node.
ReDim arrRootNodes(UBound(arrRootNodes) + 1)
arrRootNodes(UBound(arrRootNodes)) = nodeID
nodeText = Trim(arrCurrentPath(currentLevel))
nodeTag = "IGNORE"
Try
'Create the new node.
Main.tvMainNav.Nodes.Add(nodeID, nodeText)
'Reset the current working node to this root node.
currentNode = Main.tvMainNav.Nodes.Find(nodeID, False)
'Add a processing instruction.
currentNode(0).Tag = nodeTag
Catch ex As Exception
MsgBox("ERROR Creating root node. " & ex.ToString)
End Try
Else
Try
'Reset the current working node to this root node.
currentNode = Main.tvMainNav.Nodes.Find(nodeID, False)
Catch ex As Exception
MsgBox("ERROR Creating root node. " & ex.ToString)
End Try
End If
ElseIf currentLevel = 1 Then 'Major product group level.
nodeText = nodeID
nodeTag = "IGNORE"
ElseIf currentLevel = 2 Then 'Category level
If UCase(arrCurrentPath(1)) = "COLLECTIONS" Then
nodeText = nodeID
nodeTag = Main.gCategoryList.Item(nodeText).getDefaultCollectionID()
ElseIf UCase(arrCurrentPath(1)) = "INDIVIDUAL" Then
'In this case, the category is a terminal node in the tree.
nodeText = nodeID
End If
ElseIf currentLevel = 3 Then 'Product ID level, such as a design collection
' or an individual design. The name & ID of the product are both
‘ included in the node. The name is displayed.
' (theNode.name = ID, theNode.Text = ProductName)
'Get the Product ID.
nodeText = arrCurrentPath(currentLevel + 1)
' Get the product name. This will be displayed.
nodeTag = arrCurrentPath(currentLevel)
ElseIf currentLevel = 4 Then
'Ignore this level. It is the text used by level 3.
End If
'For child nodes only
If currentLevel > 0 Then
Try
If currentNode(0).Nodes.ContainsKey(nodeID) Then
currentNode = currentNode(0).Nodes.Find(nodeID, False)
addNode = False
Else
addNode = True
End If
If addNode Then
currentNode(0).Nodes.Add(nodeID, nodeText)
'Set the new node as the current node
currentNode = currentNode(0).Nodes.Find(nodeID, False)
'Add a processing instruction.
currentNode(0).Tag = nodeTag
End If
Catch x As Exception
MsgBox("Error creating child node: " & x.ToString)
End Try
End If
Next
Next
End Sub
Greg Norris
Software Developer & all around swell guy
__________________________________________________
Constructed from 100% recycled electrons.
I'm hoping that someone can point out what I cannot see myself.
I have a node at the top of my tree, which is appearing twice, and no matter what I do, I cannot make it go away.
What is even stranger, the second instance of it appears to have an unknown character appended to the beginning of the text. At least that's how it appears in the tree. It shows up as a single black rectangle. But the text file my program reads form to populate the tree doesn't contain any extra characters as far as I can see. It is delimited with VbCrlf, but I split it into an array on VbCrlf.
Is it my code, or is it the source file?
Please see my code below. Note that the source file is split into an collection of strings. First the text file is split by VbCrlf (each row is a record). These strings are then split again, and the resulting strings are held in a collection.
Any help will be much appreciated.
----------
Tree Code
----------
Public Sub fillNav(ByVal productPaths As String)
Kiosk.Main.tvMainNav.Nodes.Clear()
' Break the string containing the paths up into array, one cell per product/path.
Dim arrPaths As Array = productPaths.Split(vbCrLf)
'Split by delimiter
Dim pathColl As New Collection, currentProduct As New Product
' Break the individual path strings up into an array, one cell per
' path level. Add them to a collection.
For Each strg As String In arrPaths
pathColl.Add(strg.Split(":"))
Next
'***************************************************
'EXAMPLE OF A PATH:
'
'Designs:Individual:Birds & Butterflies:ADC-801:Butterfly
'****************************************************
Dim arrCurrentPath As Array, pathNum As Integer
'Array and boolean flag to keep track of Top level group nodes.
Dim arrRootNodes() As String = New String() {}
ReDim arrRootNodes(50)
Dim nodeExists, rootNodeExists As Boolean, rootNum, i As Integer
nodeExists = False
rootNodeExists = False
rootNum = 0
rootNodeExists = False
'################ BUILD THE TREE ################
Dim currentNode As TreeNode() = Main.tvMainNav.Nodes.Find("", False)
Dim currentLevel As Integer, nodeID, nodeText, nodeTag As String, addNode As Boolean
nodeID = ""
nodeText = ""
nodeTag = ""
addNode = False
'Loop through the collection of paths, one path at a time.
For pathNum = 1 To pathColl.Count - 1 '?? Why -1? Weird.
arrCurrentPath = pathColl(pathNum)
' Stop before the last index. The last 2 indexes are a pair.
' The first is the 'name' of the product node. The second (last) is the text displayed by that node.
For currentLevel = 0 To (UBound(arrCurrentPath) - 1)
' Index 0 is the top node of the tree.
' There can be more than one top node.
addNode = False
nodeID = Trim(arrCurrentPath(currentLevel))
If currentLevel = 0 Then
rootNodeExists = False
'Check if this node has already been created.
For i = 0 To UBound(arrRootNodes)
If arrRootNodes(i) = nodeID Then
rootNodeExists = True
Exit For
End If
Next
If Not rootNodeExists Then
'Node not found. Create the new node.
ReDim arrRootNodes(UBound(arrRootNodes) + 1)
arrRootNodes(UBound(arrRootNodes)) = nodeID
nodeText = Trim(arrCurrentPath(currentLevel))
nodeTag = "IGNORE"
Try
'Create the new node.
Main.tvMainNav.Nodes.Add(nodeID, nodeText)
'Reset the current working node to this root node.
currentNode = Main.tvMainNav.Nodes.Find(nodeID, False)
'Add a processing instruction.
currentNode(0).Tag = nodeTag
Catch ex As Exception
MsgBox("ERROR Creating root node. " & ex.ToString)
End Try
Else
Try
'Reset the current working node to this root node.
currentNode = Main.tvMainNav.Nodes.Find(nodeID, False)
Catch ex As Exception
MsgBox("ERROR Creating root node. " & ex.ToString)
End Try
End If
ElseIf currentLevel = 1 Then 'Major product group level.
nodeText = nodeID
nodeTag = "IGNORE"
ElseIf currentLevel = 2 Then 'Category level
If UCase(arrCurrentPath(1)) = "COLLECTIONS" Then
nodeText = nodeID
nodeTag = Main.gCategoryList.Item(nodeText).getDefaultCollectionID()
ElseIf UCase(arrCurrentPath(1)) = "INDIVIDUAL" Then
'In this case, the category is a terminal node in the tree.
nodeText = nodeID
End If
ElseIf currentLevel = 3 Then 'Product ID level, such as a design collection
' or an individual design. The name & ID of the product are both
‘ included in the node. The name is displayed.
' (theNode.name = ID, theNode.Text = ProductName)
'Get the Product ID.
nodeText = arrCurrentPath(currentLevel + 1)
' Get the product name. This will be displayed.
nodeTag = arrCurrentPath(currentLevel)
ElseIf currentLevel = 4 Then
'Ignore this level. It is the text used by level 3.
End If
'For child nodes only
If currentLevel > 0 Then
Try
If currentNode(0).Nodes.ContainsKey(nodeID) Then
currentNode = currentNode(0).Nodes.Find(nodeID, False)
addNode = False
Else
addNode = True
End If
If addNode Then
currentNode(0).Nodes.Add(nodeID, nodeText)
'Set the new node as the current node
currentNode = currentNode(0).Nodes.Find(nodeID, False)
'Add a processing instruction.
currentNode(0).Tag = nodeTag
End If
Catch x As Exception
MsgBox("Error creating child node: " & x.ToString)
End Try
End If
Next
Next
End Sub
Greg Norris
Software Developer & all around swell guy
__________________________________________________
Constructed from 100% recycled electrons.