Jump to content

Little Problem with _GUICtrlListViewDeleteItemsSelected


florisch
 Share

Recommended Posts

My GUI crashed when using _GUICtrlListViewDeleteItemsSelected and no item in the given listview is selected. I drilled down into AutoIt3\Include\GuiListView.au3 and found:

Func _GUICtrlListViewDeleteItemsSelected($h_listview)
    Local $i, $ItemCount
    
    $ItemCount = _GUICtrlListViewGetItemCount($h_listview)
    If (_GUICtrlListViewGetSelectedCount($h_listview) == $ItemCount) Then
        _GUICtrlListViewDeleteAllItems($h_listview)
    Else
        Local $items = _GUICtrlListViewGetSelectedIndices($h_listview, 1)
        _GUICtrlListViewSetItemSelState($h_listview, -1, 0)
        For $i = $items[0] To 1 Step - 1
            _GUICtrlListViewDeleteItem($h_listview, $items[$i])
        Next
    EndIf
EndFunc  ;==>_GUICtrlListViewDeleteItemsSelected

Nowhere is checked, if at least one item is selected. If not, _GUICtrlListViewGetSelectedIndices does not return an array and the for-loop crashes.

Is this a bug? Is it a feature I should cope with? I am no expert programmer, but I would like to have some check there if at least one item is selected. Returning $LV_ERR if not seems to be the correct behaviour.

Link to comment
Share on other sites

Func _GUICtrlListViewDeleteItemsSelected($h_listview)
    Local $i, $ItemCount
    
    $ItemCount = _GUICtrlListViewGetItemCount($h_listview)
    If (_GUICtrlListViewGetSelectedCount($h_listview) == $ItemCount) Then
        _GUICtrlListViewDeleteAllItems($h_listview)
    Else
        Local $items = _GUICtrlListViewGetSelectedIndices($h_listview, 1)
        If Not IsArray($items) Then Return SetError($LV_ERR, $LV_ERR,0)
        _GUICtrlListViewSetItemSelState($h_listview, -1, 0)
        For $i = $items[0] To 1 Step - 1
            _GUICtrlListViewDeleteItem($h_listview, $items[$i])
        Next
    EndIf
EndFunc   ;==>_GUICtrlListViewDeleteItemsSelected

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Yes something like that. But this is not my code. I worked around in my code since I do not want to run into problems with changing to the next AutoIt version which will bring a new (or unaltered) GuiListView.au3 with it.

I think this is a bug and should be fixed like you did. Shall I post again in the Bug Reports forum?

Link to comment
Share on other sites

Yes something like that. But this is not my code. I worked around in my code since I do not want to run into problems with changing to the next AutoIt version which will bring a new (or unaltered) GuiListView.au3 with it.

I think this is a bug and should be fixed like you did. Shall I post again in the Bug Reports forum?

Being I'm the author of that function, I gave you what should end up in the next beta, has already been submitted.

You can replace the function in your include for now, the next beta should have that change.

No need to post this again in bug reports.

Thanks

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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