Jump to content

Random Listbox error...


Newb
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
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).

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