#3657 closed Bug (Fixed)
Incorrect behaviour while using _GUICtrlListView_SimpleSort when no items are selected
| Reported by: | 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:2 by , on Sep 1, 2018 at 12:14:18 PM
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 by , on Sep 3, 2018 at 4:41:52 PM
You're totally right. More complex it is.
Your solution works good :-)
comment:4 by , on Sep 25, 2018 at 7:21:53 PM
| Milestone: | → 3.3.15.1 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [12167] in version: 3.3.15.1

Forgot to post the source code:
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Example()
Func Example()
EndFunc ;==>Example