Results 1 to 19 of 19

Thread: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    50

    About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    '非常感谢奥拉夫.史密斯为我们提供的强大而优秀的vbRichClient5.dll
    '现在的问题点:
    '1.动态加载数据的问题:窗体首次启动时加载前3层数据(现在使用的代码直接加载了前3层数据),如何在单击每个节点时加载节点后面2层的数据.要求数据能高效率地加载树上.
    '2.节点复选框的问题:如何修改代码,可以让树节点上的复选框可以被选中.
    '3.单击时,如何能够获取节点的Key值;
    '4.将索引/关键字/标题等内容,混合在Key值中,是否是一个好方法,有没有其它方法可以优化取代.
    '5.如何在选中/取消树控件父节点复选框时,自动选中/取消该节点下面的子节点.
    '6.如何在选中/取消树控件父节点时,自动选中/取消其上的所有父节点.
    '7.希望能够有方法将cwTree封装得简单易用.如同Treeview一样的易用.
    '请原谅我提出这么多的问题.


    ''thank God for Olaf. Smith provides us with powerful and good vbRichClient5.dll
    ''the question now point:
    Dynamic loading
    1. data problem: form when first start loading before the 3 layer data (now use the code directly loaded before the 3 layer data), how to load at each node when the node click behind the 2 layer data. Require data to be efficiently loaded on the tree.
    '2. node check box problem: how to modify the code, check can make the tree node on the box can be selected.
    3., how to obtain the node Key values;
    4. will index / keywords / Title and other content, mixed in the Key value, whether it is a good method, there is no other method can optimize the substitution.
    5. how to select / cancel the tree controls the parent node check box, a child node is automatically selected / cancel the node below.
    6. how to select / cancel the tree controls the parent node, automatically select / cancel all parent nodes on it.
    7.Hope to have a method cwTree package was simple and easy to use. Like Treeview to use.
    forgive me raise so many questions.
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by smileyoufu; Jan 24th, 2015 at 12:50 AM.

  2. #2

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    50

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

    Name:  TREE.jpg
Views: 1496
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
    Last edited by smileyoufu; Apr 25th, 2015 at 05:40 AM.

  3. #3
    PowerPoster
    Join Date
    Jun 2013
    Posts
    6,171

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

    Your example-zip is quite large (and - besides the "language-barrier" and asking too many questions at once -
    the reason why I didn't reply in your other thread - just didn't know "where to start, and make myself understood").

    @Moderators:
    It would be nice, when this thread here (which doesn't really belong into the CodeBank) could be merged
    with this earlier thread (which is already placed in the right Forum, and quite similar):
    http://www.vbforums.com/showthread.p...Client5-dll%29

    Ok, since your question is now (basically) reduced to a "performance-how-to", I'll make an attempt:

    The cwTree-Widget is a "virtual List-Control", using an external DataSource-Class (cDataSource in "Tree-Mode").

    The rendering in the cwTree-Widgets "visual Container-Rectangle" is done per OwnerDraw-Event,
    and the OwnerDrawing itself is then done only for the "currently visual lines in the Widget"
    (usually 15-30 lines on typical Control-Dimensions) - and only for those "currently visible Lines"
    will we need to access the hierarchically organized data which sits outside the Widget itself.

    It's good to keep that in mind, when you consider a performance-relevant scenario.

    So, the cwTree-Widget is not the culprit, when the performance is bad - it's instead:
    "how efficiently can you fill the cDataSource-instance which is later on bound to the cwTree-Widget".

    Well, let's see - you have a quite "broad" (many Fields) (Jet)DB-Table in an *.mdb, which in its
    first two Fields (ID and ParentNodeID) covers the hierarchical relation of its contained Records.

    That's quite common - nothing wrong so far - aside from a few (in my opinion) redundant Fields in that Table.

    Question is, how can we parse this Table (using Select-Queries, which are not performed on each and
    every single Record, to retrieve the Parent-Record (or Parent-Node) - as you did recursively in your
    Routine above.

    Here's a different approach, which performs only one Select-Query for each "Level-of-Tree-Depth" -
    and in your current Table-Data we have only a maximum Level-Depth of 5 (and thus only 5 queries
    instead of 3000 to perform)... In the code below, I've marked the used SQL in magenta:
    Edit: just seen, that you have a few Test-Nodes further down, which expand the Level-Depth to 10,
    not 5
    - but the point I tried to make is clear IMO (a largely reduced amount of Selects)...

    Code:
    Public Function BuildJSONHierarchyFromDBTable(ByVal JSONCol As cCollection, Optional ParentIDList As String = "0") As String
    Const BaseSQL$ = "Select ResTreeID, ParentNodeID From Sys_tblResTree Where ParentNodeID In ($PIDs) Order By ParentNodeID" 'order by ParentID is important for the approach
    Dim Rs As ADODB.Recordset, ParentCol As cCollection, ID$, ParentID$, LvlInfos As cCollection, PIDArr As cArrayList, i As Long
      
      Set Rs = GetRs(Replace(BaseSQL, "$PIDs", ParentIDList)) 'we select the records in Levels (using the IDs of the former Select as an In-Expression)
      If Rs.RecordCount Then
        Set LvlInfos = New_c.Collection(False, , False)
        Set PIDArr = New_c.ArrayList(vbString)
        
        Do Until Rs.EOF
          ID = Rs(0): ParentID = Rs(1) 'store the two "hierarchical ID-Values" of our Rs in two String-Variables
          If ParentIDList = "0" Then 'we are in the initial (outer) Call of this recursive routine
            Set ParentCol = JSONCol 'so the ParentCol is the (passed) initial Collection
          Else
            If IsEmpty(JSONCol(ParentID)) Then 'a Parent-Node with a new ID was found
              Set JSONCol.Prop(ParentID) = New_c.JSONObject
              If PIDArr.Count Then 'that's the indicator for a switch from one ParentID to the next one (these IDs came in sorted by the SQL)
                LvlInfos.Add ParentCol, GetCommaSepListFrom(PIDArr)
                PIDArr.RemoveAll
              End If
            End If
            Set ParentCol = JSONCol(ParentID) 'in this case the ParentCol is set, depending on each Records ParentID
          End If
          ParentCol.Prop(ID) = Empty 'this creates a new Entry in the ParentCol (we initialize with an empty Value first)
          PIDArr.Add ID 'store the current ID in a String-Array (to build the next ParentIDs-FilterList)...
          Rs.MoveNext
        Loop
        LvlInfos.Add ParentCol, GetCommaSepListFrom(PIDArr)
        
        For i = 0 To LvlInfos.Count - 1
          BuildJSONHierarchyFromDBTable LvlInfos.ItemByIndex(i), LvlInfos.KeyByIndex(i)  ' our next recursive call
        Next
      End If
      
      If ParentIDList = "0" Then BuildJSONHierarchyFromDBTable = JSONCol.SerializeToJSONString 'return a JSON-String
    End Function
    
    Private Function GetCommaSepListFrom(Arr As cArrayList) As String 'a little Helper-Function for the above DB-Table-Parser
    Dim SArr() As String
      If Arr.vType <> vbString Then Exit Function
      If Not Arr.BindToArray(SArr) Then Exit Function
      GetCommaSepListFrom = Join(SArr, ",")
      Arr.ReleaseArrayBinding SArr
    End Function
    At the end of this Routine, a simple JSON-string is returned - which can be stored (in Memory or in a DB as well) -
    I did that deliberately (loosing a bit of performance), to clearly isolate the two processes a bit:
    - Scanning of a returned (two Fields) ADO-Recordset, turning the "ID, ParentID" Fields into a true hierarchy,
    .. contained in a normal (JSON-enabled) cCollection (which, at the end of the routine is serialized into a JSON-String and destroyed)

    To save some time, one could pass the JSON-enabled Collection directly into a cDataSource-Container - and be done,
    but as said - I preferred the "inermediate JSON-string" instead, to make more clear that there "can be an isolation" from cDataSource.

    The routine for cDataSource-Filling (in Tree-Mode) from that JSON-string is comparably quite short:
    Code:
    Public Sub InitTreeDataSourceAndExpandAllNodes(strJSON As String)
      Set DS = New_c.DataSource 'create a new, empty RC5-DataSource-Instance
          DS.Init New_c.JSONDecodeToCollection(strJSON), "TreeRoot", , True  '<- set the Container-Type of our DataSource into "Tree-Mode"
          DS.Sort = "Asc" 'set the default-sort-mode
          DS.TreeNodeExpand DS.TreeRoot, True, True '<- we set the Expand-Attribute on all Nodes (from the DS-Root, using the optional DeepExpand-Param)
    End Sub
    So, the two routines above have nothing to do with the cwTree-Widget (yet) - they can be performed
    "independently from the GUI" (I did that at Form_Load - and the timing is quite good):



    Here's a small Demo, containing your Demo-DataBase as well.
    (it is recommended to download the latest vbWidgets.dll from the GitHub-Repository - and re-register it before running the Demo).

    TreeDemoADO.zip

    Olaf
    Last edited by Schmidt; May 3rd, 2015 at 11:44 PM.

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    50

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

    Olaf,Thank you for helping me!Your reply made me feel very happy.This strengthened my confidence to use vbrichclient5.dll
    Demonstrate your new , more efficient than the original increase many times;But there are several big doubts.
    1.There is more data now than ever before(+311).
    2.There are several levels is confusing.
    Please forgive my poor English and asking so many questions
    (On translation of English Google,Laugh)

    Name:  problem1.jpg
Views: 573
Size:  57.4 KB

    Name:  problem2.png
Views: 559
Size:  187.6 KB

    Thanks again

  5. #5

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    50

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

    My purpose ---- Design a menu editor.
    Through the panel tree controls to configure toolbar, menu bar configuration, configure permissions configuration, data dictionary and so on.
    These pictures are about my design ideas
    Now you want to add a checkbox in the tree control to each tree node. The node of the check box in the database corresponding to the "Enabled" field. This function has not found a method to complete.

    Name:  MenuEoitor.jpg
Views: 617
Size:  32.5 KB

    Menu Editor Form.zip
    Last edited by smileyoufu; May 2nd, 2015 at 08:14 AM.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,853

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

    Threads merged.
    Quote Originally Posted by Schmidt View Post
    @Moderators:
    It would be nice, when this thread here (which doesn't really belong into the CodeBank) could be merged
    with this earlier thread (which is already placed in the right Forum, and quite similar):
    http://www.vbforums.com/showthread.p...Client5-dll%29
    You were lucky I spotted this among all the text here before simply moving the thread... in future please use the "Report post" feature (triangle icon Name:  report-40b.png
Views: 502
Size:  250 Bytes under each post) for this kind of thing - as somebody else did on this occasion, but without any mention of merging.

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    50

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

    Thanks withheld reminder.I will remember your guidance.

  8. #8
    PowerPoster
    Join Date
    Jun 2013
    Posts
    6,171

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

    Quote Originally Posted by smileyoufu View Post
    1.There is more data now than ever before(+311).
    Ah, sorry - good catch - I made a mistake in my original "leveled approach" in post #3 of this thread
    (being a bit too optimistic there).

    I've corrected that in post #3 (including a new ScreenShot with the current timing, which is now at 400msec
    instead of the former 100msec).


    Please try to download the updated Demo-Zip from the same link in post #3 as before.

    Olaf

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2014
    Posts
    50

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

    Olaf, thank you for your timely help, the problem has been solved successfully.
    In addition to ask: how to add a checkbox in each node, related to the database in the field "Enabled" (this is every Tree should have). I tried, but without success.
    Forgive me for asking so many questions.

    Name:  Chk.png
Views: 535
Size:  120.7 KB

  10. #10
    PowerPoster
    Join Date
    Jun 2013
    Posts
    6,171

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    If you download the newest vbWidgets-Archive from GitHub beforehand, (added an additional
    Property to cwTree, which the new Code relies on) - the following Demo should do what you want:

    TreeDemoCheckBoxesADO.zip

    Here's a ScreenShot:



    HTH

    Olaf

  11. #11
    PowerPoster
    Join Date
    Jun 2013
    Posts
    6,171

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    FWIW, here a version, where I've converted the original JET-DB (Data.mdb) 1:1 to an SQLite-DB
    (Data.db3 ... using the built-in RC5-cConverter-Class).

    Not many differences Code-wise, but the converted DB is only half as large (mostly due to UTF8-Strings) -
    and the speed whilst reading the 3000 TreeNodes is now better about factor 3.

    Here's the Download-Link:
    TreeDemoSQLite.zip

    And here a ScreenShot:



    Olaf

  12. #12
    PowerPoster
    Join Date
    Jun 2013
    Posts
    6,171

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    Tuned the SQLite-version by another factor 4 now (whilst building up the initial Tree from the DB-Table).

    TreeDemoSQLite2.zip

    Think I'll leave it at that (has enough reserves for e.g. 30000 DB-Record-Elements in the Tree now) ...

    ScreenShot:



    Olaf

  13. #13
    New Member
    Join Date
    Aug 2018
    Posts
    8

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    How to put that tree as usercontroll? I want to create ocx based on sample above, thanks

  14. #14

  15. #15
    New Member
    Join Date
    Aug 2018
    Posts
    8

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    Thank You DreamManor, I'll try.

  16. #16
    New Member
    Join Date
    Aug 2018
    Posts
    8

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    Dear DreamManor,
    I Follow this link http://www.vbforums.com/showthread.p...el#post4880025 and I interested with this picture http://vbrichclient.com/Downloads/SimpleVListDemo2.png
    But the problem is if the columns with large than user control with, some column can't be visible, how can I make horizontal scrollbar visible in bottom,

    Thanks

  17. #17
    New Member
    Join Date
    Aug 2018
    Posts
    8

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    Dear DreamManor,
    I Follow this link http://www.vbforums.com/showthread.p...el#post4880025 and I interested with this picture http://vbrichclient.com/Downloads/SimpleVListDemo2.png
    But the problem is if the columns with large than user control with, some column can't be visible, how can I make horizontal scrollbar visible in bottom,

    Thanks

  18. #18
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    Quote Originally Posted by xamxul View Post
    Dear DreamManor,
    I Follow this link http://www.vbforums.com/showthread.p...el#post4880025 and I interested with this picture http://vbrichclient.com/Downloads/SimpleVListDemo2.png
    But the problem is if the columns with large than user control with, some column can't be visible, how can I make horizontal scrollbar visible in bottom,

    Thanks
    Maybe you should add an HScrollBar child control to your control.

    You can download the source code for vbWidgets from the following link:
    https://github.com/vbRichClient/vbWidgets

    Then you can see the usage of HScrollBar and VScrollBar from cwVList.cls.

    Note:
    The cwTree control is derived from the cwVList control, which has HScrollBar and VScrollBar features.
    Last edited by dreammanor; Aug 8th, 2018 at 12:46 PM.

  19. #19
    New Member
    Join Date
    Aug 2018
    Posts
    8

    Re: About cwTree control problem in vbWidgets.dll (based on vbRichClient5.dll)

    Thank You. I'll learn it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width