Opened 5 years ago

Closed 4 years ago

#3736 closed Bug (Duplicate)

_GUICtrlTreeView_Sort fails when there is just one item in TreeView

Reported by: Andy289 Owned by:
Milestone: Component: Standard UDFs
Version: Severity: None
Keywords: Cc:


I know that there is nothing to sort if you have just one item but a proper validation should be performed to avoid an array subscript dimension range exceeded error.

Func _GUICtrlTreeView_Sort($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    Local $iItemCount = _GUICtrlTreeView_GetCount($hWnd)    ; <------------- if $iItemCount = 1
    If $iItemCount Then
        Local $aTreeView[$iItemCount], $i = 0               ; <------------- this array has just an index
        ; get only A child at each level
        Local $hHandle = _GUICtrlTreeView_GetFirstItem($hWnd)
        $aTreeView[1] = $hHandle                            ; <------------- and this would fail
        $aTreeView[0] = 2
        __GUICtrlTreeView_SortGetFirstChild($hWnd, $hHandle, $aTreeView)
        ReDim $aTreeView[$aTreeView[0]]
        $aTreeView[0] = 0

        For $i = 0 To UBound($aTreeView) - 1
            _SendMessage($hWnd, $TVM_SORTCHILDREN, 0, $aTreeView[$i], 0, "wparam", "handle") ; Sort the items in root

EndFunc   ;==>_GUICtrlTreeView_Sort

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by Jpm

  • Resolution set to Duplicate
  • Status changed from new to closed

Duplicate #3714

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The ticket will remain with no owner.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.