Jump to content
Sign in to follow this  
LastSoul

listbox scroll down by click Button

Recommended Posts

LastSoul

hey guys

i tried to scroll down the select item in listbox but its select more then one item .

just need to scroll down every time i click the Button .

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <array.au3>


$Form1 = GUICreate("Form1", 254, 233, 516, 270)
$List1 = GUICtrlCreateList("", 16, 8, 217, 149, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL)) ; BitOR style taken from help file
$sItems = "1|2|3|4|5" ; To simplify, no txt list. Just this one for testing purposes.
GUICtrlSetData($List1, $sItems)
_GUICtrlListBox_SetSel($List1,0) ; Set position 1 (which is the 2nd in list) as default
$Button1 = GUICtrlCreateButton("Button1", 80, 176, 75, 25)
GUISetState(@SW_SHOW)


Local $aaa
Local $sss


While 1
    $aaa = GUIGetMsg()
    Select
        Case $aaa = $GUI_EVENT_CLOSE
            ExitLoop
        Case $aaa = $Button1
            $selItems = _GUICtrlListBox_GetSelItemsText($List1)
$sss = $sss + 1
_GUICtrlListBox_SetSel($List1, $sss); Read the selected item characteristics to an array
            MsgBox(4160, "Information", "Item Selected: " & $selItems[1]) ; $selItems[1] cooresponds to the the selected text value in this array
    EndSelect
WEnd
:sweating:

 

Share this post


Link to post
Share on other sites
BrewManNH

You never deselect the first one before moving down to the next selection. You have a MultiSelect Listbox, so you can have multiple items selected. Try this.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <array.au3>


$Form1 = GUICreate("Form1", 254, 233, 516, 270)
$List1 = GUICtrlCreateList("", 16, 8, 217, 149, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL)) ; BitOR style taken from help file
$sItems = "1|2|3|4|5" ; To simplify, no txt list. Just this one for testing purposes.
GUICtrlSetData($List1, $sItems)
_GUICtrlListBox_SetSel($List1, 0) ; Set position 1 (which is the 2nd in list) as default
$Button1 = GUICtrlCreateButton("Button1", 80, 176, 75, 25)
GUISetState(@SW_SHOW)


Local $aaa, $Selected
Local $sss = 0


While 1
    $aaa = GUIGetMsg()
    Select
        Case $aaa = $GUI_EVENT_CLOSE
            ExitLoop
        Case $aaa = $Button1
            $selItems = _GUICtrlListBox_GetSelItemsText($List1)
            $Selected = _GUICtrlListBox_GetSelItems($List1)
            _GUICtrlListBox_SetSel($List1, $Selected[1], False)
            $sss = $sss + 1
            If $sss = _GUICtrlListBox_GetCount($List1) Then $sss = 0
            _GUICtrlListBox_SetSel($List1, $sss); Read the selected item characteristics to an array
            MsgBox(4160, "Information", "Item Selected: " & $selItems[1]) ; $selItems[1] cooresponds to the the selected text value in this array
    EndSelect
WEnd

You'll see that I also fixed an issue you would have had even if this had worked as intended, you counted up and selected the next item in the list, but you never took into account that eventually you'd end up at the bottom of the list and your script would have crashed when you ran out of items. I made it so that it wraps back to the first item in the list instead of crashing. If you wanted it to stay at the last item in the list after you've scrolled down to it, change this line.

; From this
If $sss = _GUICtrlListBox_GetCount($List1) Then $sss = 0
; To this
If $sss = _GUICtrlListBox_GetCount($List1) Then $sss = _GUICtrlListBox_GetCount($List1) - 1
  • Like 1

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
TheSaint

OOPS, too slow ... should have guessed BrewManNH would be on the job.

You need to get the selected index first, every time you click the button, then increment it by one.

That requires the following to be in your Button code

$iIndex = _GUICtrlListBox_GetCurSel($hWnd)

$iIndex = $iIndex + 1

_GUICtrlListBox_SetCurSel($hWnd, $iIndex)

You should also use

_GUICtrlListBox_GetCount($hWnd)

so that you can modify what happens when you get to the end of your list.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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  

×