嘿我试图在树视图中添加第二级,第一级是GroupName,第二级是描述
我有这段代码,但只为每个节点创建单独的节点,而不是在不同的组名下
Sub LoadGroupTree()
'**Loads Property List
' Initialise Error Checking
' Dimension Local Variables
Dim uRecSnap As ADODB.Recordset
Dim uPar As ADODB.Parameter
Dim uNode As TreeNode
' Dim iGroupID As Integer = 0
Dim uStackframe As New Diagnostics.StackFrame
Try
' Check For Open Connection
If uDBase Is Nothing Then
OpenConnection()
bConnection = True
End If
' Run Stored Procedure - Load Property List (Based on Search Value)
uCommand = New ADODB.Command
With uCommand
.ActiveConnection = uDBase
.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
.CommandTimeout = 0
uPar = .CreateParameter("@SearchValue", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 30)
.Parameters.Append(uPar)
.Parameters("@SearchValue").Value = txtFilter.Text
.CommandText = "InspsectionGroup_LoadRecords"
uRecSnap = .Execute
End With
' Suppress TreeView Repaint / Clear TreeView
tvwInspectionGroups.BeginUpdate()
tvwInspectionGroups.Nodes.Clear()
tvwInspectionGroups.ShowNodeToolTips = True
' Populate List
Do Until uRecSnap.EOF
uNode = tvwInspectionGroups.Nodes.Add("P" & Format(uRecSnap("InspectionGroupID").Value, "0000"), uRecSnap("GroupName").Value)
uNode.Tag = "P:" & Format(uRecSnap("InspectionGroupID").Value, "0000") & ":01:"
uNode.Nodes.Add("D" & Format(uRecSnap("GroupName").Value, "0000"), uRecSnap("Description").Value)
uNode.Tag = "D:" & Format(uRecSnap("GroupName").Value, "0000") & ":02:"
uNode.Nodes.Add("A" & Format(uRecSnap("Description").Value, "0000"), uRecSnap("AddressLine1").Value)
uNode.Tag = "A:" & Format(uRecSnap("Description").Value, "0000") & ":03:"
uRecSnap.MoveNext()
Loop
uRecSnap.Close()
' Repaint TreeView.
tvwInspectionGroups.EndUpdate()
tvwInspectionGroups.Refresh()
' Close Connection
Catch ex As Exception
' Catch Error
If Err.Number <> 0 Then
WriteAuditLogRecord(uStackframe.GetMethod.DeclaringType.FullName, uStackframe.GetMethod.Name.ToString, "Error", Err.Description & vbCrLf & vbCrLf & ex.StackTrace, 0)
MsgBox("System Error Ref: " & sAuditID & vbCrLf & uStackframe.GetMethod.DeclaringType.FullName & " / " & uStackframe.GetMethod.Name.ToString & vbCrLf & Err.Description & vbCrLf & vbCrLf & ex.StackTrace & Chr(13) & sErrDescription, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Business Management System - Unexepected Error Ref: " & sAuditID)
End If
Finally
If bConnection Then CloseConnection()
uRecSnap = Nothing
End Try
答案 0 :(得分:0)
Sub LoadGroupTree()
'**Loads Property List
' Initialise Error Checking
' Dimension Local Variables
Dim uRecSnap As ADODB.Recordset
Dim uPar As ADODB.Parameter
Dim uNode As TreeNode
Dim uNode3 As TreeNode
' Dim iGroupID As Integer = 0
Dim uStackframe As New Diagnostics.StackFrame
Try
' Check For Open Connection
If uDBase Is Nothing Then
OpenConnection()
bConnection = True
End If
' Run Stored Procedure - Load Property List (Based on Search Value)
uCommand = New ADODB.Command
With uCommand
.ActiveConnection = uDBase
.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
.CommandTimeout = 0
uPar = .CreateParameter("@SearchValue", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 30)
.Parameters.Append(uPar)
.Parameters("@SearchValue").Value = txtFilter.Text
.CommandText = "InspsectionGroup_LoadRecords"
uRecSnap = .Execute
End With
' Suppress TreeView Repaint / Clear TreeView
tvwInspectionGroups.BeginUpdate()
tvwInspectionGroups.Nodes.Clear()
tvwInspectionGroups.ShowNodeToolTips = True
' Populate List
Do Until uRecSnap.EOF
uNode = tvwInspectionGroups.Nodes.Add("P" & Format(uRecSnap("InspectionGroupID").Value, "0000"), uRecSnap("GroupName").Value)
uNode.Tag = "P:" & Format(uRecSnap("InspectionGroupID").Value, "0000") & ":01:"
uNode3 = uNode.Nodes.Add("D" & Format(uRecSnap("GroupName").Value, "0000"), uRecSnap("Description").Value)
uNode.Tag = "D:" & Format(uRecSnap("GroupName").Value, "0000") & ":02:"
uNode3.Nodes.Add("A" & Format(uRecSnap("Description").Value, "0000"), uRecSnap("AddressLine1").Value)
uNode3.Tag = "A:" & Format(uRecSnap("Description").Value, "0000") & ":03:"
uRecSnap.MoveNext()
Loop
uRecSnap.Close()
' Repaint TreeView.
tvwInspectionGroups.EndUpdate()
tvwInspectionGroups.Refresh()
' Close Connection
Catch ex As Exception
' Catch Error
If Err.Number <> 0 Then
WriteAuditLogRecord(uStackframe.GetMethod.DeclaringType.FullName, uStackframe.GetMethod.Name.ToString, "Error", Err.Description & vbCrLf & vbCrLf & ex.StackTrace, 0)
MsgBox("System Error Ref: " & sAuditID & vbCrLf & uStackframe.GetMethod.DeclaringType.FullName & " / " & uStackframe.GetMethod.Name.ToString & vbCrLf & Err.Description & vbCrLf & vbCrLf & ex.StackTrace & Chr(13) & sErrDescription, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Business Management System - Unexepected Error Ref: " & sAuditID)
End If
Finally
If bConnection Then CloseConnection()
uRecSnap = Nothing
End Try