I ported a VB6 application to VB .Net 2003 and I am having a problem loading a TreeView control correctly. This code worked fine in VB6 but the functionality of the Treeview.Nodes.Add function has changed. Basically, this application allows a user to extract check-out information and check-in comments from a SourceSafe DB. I load the Treeview control with a list of the SourceSafe Projects in the identified SourceSafe DB.
The sub I use to fill the Treeview control is called recursively. Here is the code for I am using.
First I realize the error handling section needs to be corrected using the .Net Try..Except..Finally method but that isn't my immediate problem. My problem is when I recursively call the sub, how do I identify the parent node to which I should add this child node. In VB6 the Node.Add function let me pass in a relative reference (parent key), the relationship type (Child), key for the new node, and the node text. In the .Net version it is basically Node.Add (node text) so somehow I need to point the node to the nodes parent. I was trying this by passing in the Node.Index of the node I just created but that doesn’t work.
What I should get is the following
What I actually get is the following
And that’s it. As you can see, AFCEE_Access and AFCEE Data Gathering are not children to MXT and also there aren’t any other children.
Can anyone suggest a solution to my problem?
Thanks
Richard Anderson
The sub I use to fill the Treeview control is called recursively. Here is the code for I am using.
VB.NET:
Public Sub PopulateVSSTree(ByRef tvwControl As TreeView, ByVal intParentNode As Integer, ByRef objVSSDatabase As SourceSafeTypeLib.VSSDatabase, Optional ByVal szProjectRoot As String = "$/", Optional ByVal bIncludeFiles As Boolean = True)
Static iTreeLevel As Short
Dim objVSSItem As SourceSafeTypeLib.VSSItem
Dim tvwNode As TreeNode
Dim strNodeName As String
On Error GoTo Err_handler
If iTreeLevel = 0 Then
SmartClearNodes(tvwControl)
strNodeName = szProjectRoot.ToString()
tvwNode = New TreeNode(strNodeName)
tvwControl.Nodes.Add(tvwNode)
End If
iTreeLevel = iTreeLevel + 1
If objVSSDatabase.VSSItem(szProjectRoot).Type = SourceSafeTypeLib.VSSItemType.VSSITEM_PROJECT Then
For Each objVSSItem In objVSSDatabase.VSSItem(szProjectRoot).Items()
If objVSSItem.Type = SourceSafeTypeLib.VSSItemType.VSSITEM_PROJECT Then
strNodeName = objVSSItem.Name
tvwNode = New TreeNode(strNodeName)
tvwControl.Nodes(intParentNode).Nodes.Add(tvwNode)
PopulateVSSTree(tvwControl, tvwNode.Index(), objVSSDatabase, szProjectRoot & objVSSItem.Name.ToString & "/", bIncludeFiles)
Else
If bIncludeFiles Then
strNodeName = objVSSItem.Name
tvwNode = New TreeNode(strNodeName)
tvwControl.Nodes(intParentNode).Nodes.Add(tvwNode)
End If
End If
Next objVSSItem
End If
Exit_Sub:
iTreeLevel = iTreeLevel - 1
Exit Sub
Err_handler:
iTreeLevel = 0
Err.Raise(Err.Number, Err.Source, Err.Description)
End Sub
First I realize the error handling section needs to be corrected using the .Net Try..Except..Finally method but that isn't my immediate problem. My problem is when I recursively call the sub, how do I identify the parent node to which I should add this child node. In VB6 the Node.Add function let me pass in a relative reference (parent key), the relationship type (Child), key for the new node, and the node text. In the .Net version it is basically Node.Add (node text) so somehow I need to point the node to the nodes parent. I was trying this by passing in the Node.Index of the node I just created but that doesn’t work.
What I should get is the following
VB.NET:
$/
- MXT
AFCEE _Access
- AFCEE Data Gathering
Database
Documentation
- Final Report
Final Documentation
FinalizedProcesses
- CCB
PMR
....
Etc, etc.
VB.NET:
$/
MXT
AFCEE _Access
AFCEE Data Gathering
And that’s it. As you can see, AFCEE_Access and AFCEE Data Gathering are not children to MXT and also there aren’t any other children.
Can anyone suggest a solution to my problem?
Thanks
Richard Anderson