Jump to content

How to search in treeview (virtual)? It's too slow currently


Recommended Posts

@KaFu  Just was thinking the same

Here my searchItem to make it look faster :

Func _searchitem()
  Local $sSearch = GUICtrlRead($sEARCHinput), $iFind = 0
  GUICtrlSetData($edit_searchresult, "")
  For $i = 0 To UBound($aItems) - 1
    If StringInStr($aItems[$i], $sSearch) Then
      GUICtrlSetData($edit_searchresult, StringSplit($aItems[$i], "#", 2)[1] & @CRLF, 1)
      _GUICtrlTreeView_Expand($idTreeView, $aPath[$i][1], True)
      _GUICtrlTreeView_SetSelected($idTreeView, $aPath[$i][1], True)
      If Not $iFind Then
        $iFind = $aPath[$i][1]
        ControlFocus($hGui, "", $idTreeView)
        _GUICtrlTreeView_SelectItem($idTreeView, $iFind)
        _GUICtrlTreeView_BeginUpdate($idTreeView)
      EndIf
    EndIf
  Next
  If $iFind Then
    _GUICtrlTreeView_EndUpdate($idTreeView)
    _GUICtrlTreeView_SelectItem($idTreeView, $iFind, $TVGN_FIRSTVISIBLE)
  EndIf
EndFunc   ;==>_searchitem

 

Edited by Nine
Link to comment
Share on other sites

Or maybe this?

Func _searchitem()
    Local $sSearch = GUICtrlRead($sEARCHinput), $iFind = 0
    _GUICtrlTreeView_BeginUpdate($idTreeView)
    For $i = 0 To UBound($aItems) - 1
        If StringInStr($aItems[$i], $sSearch) Then
            GUICtrlSetData($edit_searchresult, "", 1)
            GUICtrlSetData($edit_searchresult, StringSplit($aItems[$i], "#", 2)[1] & @CRLF, 1)
            _GUICtrlTreeView_Expand($idTreeView, $aPath[$i][1], True)
            _GUICtrlTreeView_SetSelected($idTreeView, $aPath[$i][1], True)
            If Not $iFind Then
                $iFind = $aPath[$i][1]
                ControlFocus($hGui, "", $idTreeView)
                _GUICtrlTreeView_SelectItem($idTreeView, $iFind)

            EndIf
        EndIf
    Next
    If $iFind Then
        _GUICtrlTreeView_SelectItem($idTreeView, $iFind, $TVGN_FIRSTVISIBLE)
    EndIf
    _GUICtrlTreeView_EndUpdate($idTreeView)
EndFunc   ;==>_searchitem

 

Edited by KaFu
Link to comment
Share on other sites

My idea was to show a first result as fast as possible, to make it look instantly, then do the rest in background.  You can test it with a lot of matches, you will see the difference...

Edited by Nine
Link to comment
Share on other sites

Good idea, I do something like that in SMF too :), first parse the visible results of a listview enclosed by _GUICtrlListView_BeginUpdate() and _GUICtrlListView_EndUpdate(), and after that add the invisible results outside. Up to the Op which way to go.

Link to comment
Share on other sites

A possible change in search code :

; _GUICtrlTreeView_Expand($idTreeView, $aPath[$i][1], True)
_GUICtrlTreeView_EnsureVisible($hTreeView, $aPath[$i][1])

For example, a search on "abv" would unnecessarily expand the 3rd match like this :

1043589359_TreeView4a.png.428cae3895f1581553ac3a5ff8bbed04.png

Instead of the following (which seems more correct) :

2106383299_TreeView4b.png.c2f35df6b04d9da5facc82a28b596b7c.png

I just discovered that OP's original code was based on LarsJ's thread ("3) Semi-Virtual TreeView.au3")

455830992_LarsJTreeView.png.9ddb32cef3afb7da7d99f7ddffb9c3f8.png

His examples 4) and 5) look very interesting, making the TreeView virtual. Nearly same code in 4) and 5) , except 5) uses a 100.000 rows text file.

As I never approached the TreeView control (until the current thread) then it's time to begin :)

Link to comment
Share on other sites

Yes, I referred the 3) Semi-Virtual, as it's faster to build a treeview from a big txt file.

the 4) virtual Treeview.au3 seems has some issues, if the .txt items like:

image.png.c3b594de07467630aa5e39a03f3f8816.png

The 2|001|0|20 and its child will lose.

 

Also, the .txt file column 2, which is indicating how many child items under the parent,

but if the original .txt format is below, it's hard to figure out the count in column 2, I don't have any idea to transfer it so far.

aaaaaaaaaa
   bbbbbbbbbbb
      cccccccccc
         ddddddddddddddd
   eeeeeeeeeeeeee
      ffffffffffffff
         gggggggggggg
         hhhhhhhhhhhh
         iiiiiiiiiiii
         jjjjjjjjjjjj
         kkkkkkkkkkkk
            llllllllllll
         nnnnnnnnnnnn

image.png.d2a8d90f91f82d01771410619cb53728.png

 

Link to comment
Share on other sites

@September I wish LarsJ was here to respond your question but it's been several months he's not on the Forum.

The code he presented for his virtual treeview (examples 4 & 5) seem to work only when children are created at the same sublevel, then the next node expands to a higher level etc... until it comes back to the root for a new cycle. After children were created at a certain level, all items created at a lower level  don't seem to show. Maybe he did this purposely, or it's a bug which could be fixed when he comes back.

So what works with this text file in example 3 ("semi virtual treeview") ...

1870568430_TreeView5aok.png.3c5ed69596145191aa2cfdbf25a2ff52.png

... doesn't seem to work when applied to his virtual treeview code, as showed in your precedent post. Here is a shorter example of the issue, where item3 doesn't show because it's placed at a lower level (1) when children have already been created at a higher level (item2 at level 2)

1028630223_TreeView5bok.png.2293d297c7543d063f7275eed74ca0f5.png

While waiting for LarsJ's return, if someone has an idea about this possible issue, thanks for sharing your thoughts.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...