Sign in to follow this  
Followers 0
Newb

Random Listbox error...

5 posts in this topic

#1 ·  Posted (edited)

Hi all,

This is what i get

Posted Image

With this code

#include <GuiListBox.au3>
$GuiPrincipale = GUICreate("New Gui", 802, 617, 156, 96)
GUICtrlCreateGroup("Features", 16, 512, 273, 57)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Checkbox2 = GUICtrlCreateCheckbox("actions", 24, 536, 161, 17)
$List = GUICtrlCreateList("", 184, 528, 97, 34)
GUICtrlSetData(-1, "1-5 Seconds|1-10 Seconds|1-15 Seconds|1-20 Seconds|1-25 Seconds|1-30 Seconds")
_GUICtrlListBox_SetItemData($List,0,5)
_GUICtrlListBox_SetItemData($List,1,10)
_GUICtrlListBox_SetItemData($List,2,15)
_GUICtrlListBox_SetItemData($List,3,20)
_GUICtrlListBox_SetItemData($List,4,25)
_GUICtrlListBox_SetItemData($List,5,30)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Why the hell the first item is dropped bottom list? :)

As u see the order is:

GUICtrlSetData(-1, "1-5 Seconds|1-10 Seconds|1-15 Seconds|1-20 Seconds|1-25 Seconds|1-30 Seconds")
Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

When you created your ListBox, you did not specify a style, so the defaults were used. The defaults for the listbox are:

$LBS_SORT, $WS_BORDER, $WS_VSCROLL

$LBS_SORT is sorting the list, and 1-5 is the last (highest) item when the list is sorted. You must do one of two things:

Format your numbers so that the desired sort occurs

OR

You should define your style (and add necessary includes) to remove $LBS_SORT:

#include <GuiListBox.au3>
#include <WindowsConstants.au3>

$GuiPrincipale = GUICreate("New Gui", 802, 617, 156, 96)
GUICtrlCreateGroup("Features", 16, 512, 273, 57)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Checkbox2 = GUICtrlCreateCheckbox("actions", 24, 536, 161, 17)
$List = GUICtrlCreateList("", 184, 528, 97, 34, $WS_BORDER + $WS_VSCROLL)
GUICtrlSetData(-1, "1-5 Seconds|1-10 Seconds|1-15 Seconds|1-20 Seconds|1-25 Seconds|1-30 Seconds")
_GUICtrlListBox_SetItemData($List, 0, 5)
_GUICtrlListBox_SetItemData($List, 1, 10)
_GUICtrlListBox_SetItemData($List, 2, 15)
_GUICtrlListBox_SetItemData($List, 3, 20)
_GUICtrlListBox_SetItemData($List, 4, 25)
_GUICtrlListBox_SetItemData($List, 5, 30)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by Varian

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

When you created your ListBox, you did not specify a style, so the defaults were used. The defaults for the listbox are:

$LBS_SORT, $WS_BORDER, $WS_VSCROLL

$LBS_SORT is sorting the list, and 1-5 is the last (highest) item when the list is sorted. You must do one of two things:

Format your numbers so that the desired sort occurs

OR

You should define your style (and add necessary includes) to remove $LBS_SORT:

#include <GuiListBox.au3>
#include <WindowsConstants.au3>

$GuiPrincipale = GUICreate("New Gui", 802, 617, 156, 96)
GUICtrlCreateGroup("Features", 16, 512, 273, 57)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Checkbox2 = GUICtrlCreateCheckbox("actions", 24, 536, 161, 17)
$List = GUICtrlCreateList("", 184, 528, 97, 34, $WS_BORDER + $WS_VSCROLL)
GUICtrlSetData(-1, "1-5 Seconds|1-10 Seconds|1-15 Seconds|1-20 Seconds|1-25 Seconds|1-30 Seconds")
_GUICtrlListBox_SetItemData($List, 0, 5)
_GUICtrlListBox_SetItemData($List, 1, 10)
_GUICtrlListBox_SetItemData($List, 2, 15)
_GUICtrlListBox_SetItemData($List, 3, 20)
_GUICtrlListBox_SetItemData($List, 4, 25)
_GUICtrlListBox_SetItemData($List, 5, 30)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

It works, but i really didn't get your explanation :) Gotta look in the help file deeply

Thanks

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites

It works, but i really didn't get your explanation :) Gotta look in the help file deeply

Thanks

It's pretty simple. When you created your ListBox, you went with the default style (since you did not specify any style). The default style is the same as adding $LBS_SORT + $WS_BORDER + $WS_VSCROLL in the style option.

You did not want to use sort ($LBS_SORT), because the "1-5" would have been last in the list. If you had made it "1-05" it would have been first and you would have had your expected results.

In order to do that, you must specify what styles to use, as though you were adding extra styles to the ListBox. In order to specify the styles manually, you must include whatever files that define those styles. In this case, I only used $WS_BORDER + $WS_VSCROLL which are both defined in WindowsConstants.au3

You can also negate styles, but that is more complicated (in my opinion).

Share this post


Link to post
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
Sign in to follow this  
Followers 0