Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

Help me: vbRichClient5->vbWidgets-TreeTest--Tree loading speed

$
0
0
Name:  TREE.jpg
Views: 39
Size:  27.7 KB

1.Slow loading
2.3000 data takes 5 seconds
3.Hope I can help to optimize the code, improve the speed of data loading
4.Whether JSON can be used to load the data string tree control
5.If there is a need to make the data in the table with the JSON string is loaded into the tree control, how to realize the
''cModel.cls - > This code is running slow

Private Function LoadTreeNode(ParentNode As cCollection, Optional lngParentNodeID As Long = 0, Optional eumTreeDataLoadMode As eumTreeDataLoadMode = LoadOne) 'As cCollection
Dim i As Long
Dim lngChildNodeCount As Long '子节点数量
Dim ChildNode As cCollection '定义子节点
Dim strSQL As String 'SQL语句
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim rst As New ADODB.Recordset ' cRecordset
Dim sRstTemp As New ADODB.Recordset
Dim P As Long

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If DV.Exists(CStr(lngParentNodeID)) Then Exit Function '如果父节点已经存在,就退出函数
DV.Add CStr(lngParentNodeID), CStr(lngParentNodeID) '否则就新增到容器,以便检查是否重复
strSQL = "SELECT * FROM " & m_strTableName & " WHERE ParentNodeID=" & lngParentNodeID '组织SQL语句
' Set rst = sCnn.OpenRecordset(strSQL, False) '根据父节点ID打开对应的记录集
rst.Open strSQL, cn, 0, 1
If rst.EOF Then Exit Function ''如果打开记录集为空,就退出函数


For i = 1 To rst.RecordCount '遍历所有记录集
If colChildNode.Exists(CStr(rst(0))) Then
lngChildNodeCount = 1 '如果存在子节点(子节点数>0)
'当作节点添加
Set ChildNode = DataSource.TreeNodeAdd(ParentNode, rst("ResTreeID") & "|" & rst("ImageKey") & "|" & rst("Caption") & "|" & lngChildNodeCount & "|" & rst("FontBold") & "|" & rst("ForeColor") & "|" & rst("Enabled") & "|" & rst("Expanded") & "|", New_c.Collection(False, TextCompare, False), True)
If eumTreeDataLoadMode = LoadOne Then '如果加载1层,就啥也不用再干了

ElseIf eumTreeDataLoadMode = LoadTwo Then '如果加载2层
LoadTreeNode ChildNode, rst(0), LoadOne '就再加载1层
ElseIf eumTreeDataLoadMode = LoadAll Then '如果加载全部
LoadTreeNode ChildNode, rst(0), eumTreeDataLoadMode '使用递归加载全部节点
End If
Else '如果不存在子节点(子节点数<=0)
'否则就当作末级节点添加
lngChildNodeCount = 0
ParentNode.Add Empty, rst("ResTreeID") & "|" & rst("ImageKey") & "|" & rst("Caption") & "|" & lngChildNodeCount & "|" & rst("FontBold") & "|" & rst("ForeColor") & "|" & rst("Enabled") & "|" & rst("Expanded") & "|"
End If
lngLoadProgress = lngLoadProgress + 1 '进度计数器+1
If lngLoadProgress Mod 30 = 0 Then Tree.Caption = "正在加载 第 " & lngLoadProgress & " 条"
DoEvents '释放控制权,防止假死
' Debug.Print i & " - " & Time
rst.MoveNext '指针移动到下一条记录
Next
End Function


vbWidgets-TreeTest.zip
Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>