Jump to content

_GUICtrlComboBox_GetTopIndex() always returns 0


Recommended Posts

I'm having a problem where the _GUICtrlComboBox_GetTopIndex() function always returns zero.

I ran the _GUICtrlComboBox_GetTopIndex.au3 example provided with the AutoIt installation and got zero there, too.

Here is the _GUICtrlComboBox_GetTopIndex.au3 code:

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hCombo

    ; Create GUI
    GUICreate("ComboBox Get Top Index", 400, 296)
    $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296, BitOR($CBS_SIMPLE, $CBS_DISABLENOSCROLL, $WS_VSCROLL))
    GUISetState()

    ; Add files
    _GUICtrlComboBox_BeginUpdate($hCombo)
    _GUICtrlComboBox_AddDir($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate($hCombo)

    ; Set Top Index
    _GUICtrlComboBox_SetTopIndex($hCombo, 10)

    ; Get Top Index
    MsgBox(4160, "Information", "Top Index:" & @TAB & _GUICtrlComboBox_GetTopIndex($hCombo))

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main
Link to comment
Share on other sites

Zero is the correct result. The top visible item is also the first 0-based item if the list is not longer than the control. The attempt to set the top index to 10 fails if the list isn't long enough to scroll that to the top. Try changing the directory from @WindowsDir to @SystemDir.

:)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Just wanted to also say you could use something along the lines of

Global $j = GUICtrlRead($$hCombo)

And it will get the value you want I think.

Also ty, unknowingly you have solved my problem by helping me find "_GUICtrlComboBox_GetCurSel ".

Ty :)

Edited by Tomoya
Link to comment
Share on other sites

Just wanted to also say you could use something along the lines of

Global $j = GUICtrlRead($$hCombo)

And it will get the value you want I think.

Also ty, unknowingly you have solved my problem by helping me find "_GUICtrlComboBox_GetCurSel ".

Ty ;)

How is that related to the top index? I think you're mixing stuff.

:)

Link to comment
Share on other sites

Oh, I see. The _GUICtrlComboBox_GetTopIndex() function returns the index of the item being displayed at the top of the pull down ("first visible item", as it says in the help text). I didn't read it carefully enough.

I'm still left with a problem though. When I initially populate my drop down, I seem to get the currently selected item twice in the list. Because it's not really related to this thread, I'll do a little more research and submit a new post.

Thank you for the help.

Andy :)

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