Jump to content

[Solved] Problem on auto selecting stuff in listbox


hcI
 Share

Recommended Posts

Hello

Today I'm working on listbox but there might be something that I'm missing...

I made a little script that allow the user to swap 2 items for the listbox. So the user select for example the 3rd item, press the button "Up" and it switch with the 2nd one, same with the "Down" button that switch with the 4th one.

But when I select the 3rd item and switch it the item become unselected and I would like to select it again after the manipulation :

Spoiler
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>

Opt("GUIOnEventMode", 1)

GUICreate("Test", 300, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_1Close")
$btn_up = GUICtrlCreateButton("Up", 16, 64, 47, 25)
GUICtrlSetOnEvent($btn_up, "btn_upClick")
$btn_down = GUICtrlCreateButton("Down", 67, 64, 47, 25)
GUICtrlSetOnEvent($btn_down, "btn_downClick")
$list_action = GUICtrlCreateList("", 10, 98, 165, 118, BitOR($LBS_NOTIFY,$WS_VSCROLL,$WS_BORDER))
GUICtrlSetData($list_action, "a|b|c|x|n")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Global $tmp2, $tmp3

Func GUI_1Close()
Exit
EndFunc

Func btn_upClick()
If Not GUICtrlRead($list_action) = "" Then
    $tmp2 = _GUICtrlListBox_GetCurSel($list_action)
    If $tmp2 <> 0 Then
        _GUICtrlListBox_SwapString ($list_action, $tmp2, $tmp2-1)
        MsgBox(0,"", $tmp2-1)
        _GUICtrlListBox_SetSel($list_action, $tmp2-1) ; Trying to re-select it after but, it don't do anything
    EndIf
EndIf
EndFunc

Func btn_downClick()
If Not GUICtrlRead($list_action) = "" Then
    $tmp3 = _GUICtrlListBox_GetCurSel($list_action)
    MsgBox(64,"",$tmp3&" / "&(_GUICtrlListBox_GetCount($list_action)-1))
    If $tmp3 <> (_GUICtrlListBox_GetCount($list_action)-1) Then
        _GUICtrlListBox_SwapString ($list_action, $tmp3, $tmp3+1)
        MsgBox(0,"", $tmp3+1)
        _GUICtrlListBox_SetSel($list_action, $tmp3+1) ; Trying to re-select it after but, it don't do anything
    EndIf
EndIf
EndFunc

 

As you can see in the comment of the script, _GUICtrlListBox_SetSel don't highlight/select them once the swap process is done..

What am I missing ?

Edited by hcI
Solved
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

×
×
  • Create New...