Modify

Opened 6 years ago

Closed 6 years ago

#3657 closed Bug (Fixed)

Incorrect behaviour while using _GUICtrlListView_SimpleSort when no items are selected

Reported by: s.smeitz@… Owned by: Melba23
Milestone: 3.3.15.1 Component: AutoIt
Version: 3.3.14.2 Severity: None
Keywords: Cc:

Description

When using a ListView (singlesel not enabled) which is populated with a number of items and none are selected using _GUICtrlListView_SimpleSort will select an single item.

This is due to incorrect handling of the Stringsplit function in the _GUICtrlListView_SimpleSort function written in GuiListView.au3.

If no items are selected _GUICtrlListView_GetSelectedIndices with the default settings returns an empty string. If no separatorchars are found Stringsplit will return an array with two elements being [0] = 1 and [1] = whole string = "" which is default behaviour.

Later in the _GUICtrlListView_SimpleSort a for loop is used based on the first element of the Stringsplit return array. I.e. it uses the fact that there is one item selected in the Listview which is of course incorrect. This results in having one item selected after the SimpleSort.

Suggested fix:
After StringSplit check for errors and modify array[0] to 0 if an error.

if @error = 1 Then $aSelectedItems[0] = 0

Attachments (0)

Change History (4)

comment:1 Changed 6 years ago by s.smeitz@…

Forgot to post the source code:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Example()

Func Example()

GUICreate("listview items", 220, 250, 100, 200)

Local $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
Local $idButton = GUICtrlCreateButton("Sort", 75, 170, 70, 20)
Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1

Switch GUIGetMsg()

Case $GUI_EVENT_CLOSE

ExitLoop

Case $idButton

Msgbox($MB_OK,"Items selected?","Number items selected: " & _GUICtrlListView_GetSelectedCount($idListview))

_GUICtrlListView_SimpleSort($idListview,False,0)

Msgbox($MB_OK,"Items selected?","Number items selected: " & _GUICtrlListView_GetSelectedCount($idListview))

Case $idListview

MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)

EndSwitch

WEnd

EndFunc ;==>Example

comment:2 Changed 6 years ago by Melba23

It always helps to post runnable code - but I see the problem.

The problem is more complex that you suggest as there are 3 possible situations:

  • No selection: returns empty string (no delimiters)
  • Single selection: returns single index (no delimiters)
  • Multiple selections: returns delimited string of indices

I have come up with the following code to replace the current version:

Local $aSelectedItems = StringSplit(_GUICtrlListView_GetSelectedIndices($hWnd), $vSeparatorChar)

becomes

Local $sSelectedItems = _GUICtrlListView_GetSelectedIndices($hWnd)
Switch $sSelectedItems
	Case "" ; No selection
		Local $aSelectedItems[1] = [0]
	Case Else
		StringReplace($sSelectedItems, $vSeparatorChar, "")
		Switch @extended
			Case 0 ; Single selection
				Local $aSelectedItems[2] = [1, $sSelectedItems]
			Case Else ; Multiple selections
				Local $aSelectedItems = StringSplit(_GUICtrlListView_GetSelectedIndices($hWnd), $vSeparatorChar)
		EndSwitch
EndSwitch

Try it and see if it works for you as well as it does for me.

M23

comment:3 Changed 6 years ago by s.smeitz@…

You're totally right. More complex it is.

Your solution works good :-)

comment:4 Changed 6 years ago by Melba23

  • Milestone set to 3.3.15.1
  • Owner set to Melba23
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [12167] in version: 3.3.15.1

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

Action
as closed The owner will remain Melba23.
Author


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

 
Note: See TracTickets for help on using tickets.