簡體   English   中英

如何將級別添加到TreeView

[英]How to add Levels to TreeView

嘿我試圖在樹視圖中添加第二級,第一級是GroupName,第二級是Description

我有這個代碼,但只是為每個創建單獨的節點,而不是在不同的組名下

 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
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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM