Jump to content

controllistview move to selected item?


rusty1201
 Share

Recommended Posts

Hey guys - I've been pouring through topics on controlling a "SysListView" box and I've basically got it working, but now that I've found the item I want and have it selected I can't figure out how to actually focus it / double-click on it. Here's what I need to do:

Select an item in a list box of about 3000 items (done this)

Scroll down to where that selected item is (?)

Double-click that item

The problem is that after I select the item the box doesn't scroll itself down to the selected item, and there is no other method in the program I'm trying to automate other than double-clicking to make the selection go. If I try pressing enter or space or whatever after the item is selected by AutoIT nothing happens, I have to manually scroll down, find the item I've selected and then double-click it, which obviously isn't going to work.

Here's my code so far:

$gametype = "Yellow"
$opts = "Large"
$chnd = ControlGetHandle("Mygame", "", "SysListView322")

for $i = controllistview ("Mygame", "", "SysListView322", "GetItemCount") to 1 step -1
$txt = controllistview ("Mygame", "", "SysListView322", "GetText", $i, 2)
    if $txt = $gametype Then
        $txt = controllistview ("Mygame", "", "SysListView322", "GetText", $i, 4)
        if $txt = $opts Then
            controllistview ("Mygame", "", "SysListView322", "Select", $i)
            msgbox (0, "", "Found and selected item!")
            WinActivate ("Mygame")
            quitnow ()
        endIf
    endIf
Next

Any ideas??!

Thanks!!

Link to comment
Share on other sites

Try this:

#Include <GuiListView.au3>

$gametype = "Yellow"
$opts = "Large"
$chnd = ControlGetHandle("Mygame", "", "SysListView322")

for $i = controllistview ("Mygame", "", "SysListView322", "GetItemCount") to 1 step -1
 $txt = controllistview ("Mygame", "", "SysListView322", "GetText", $i, 2)
    if $txt = $gametype Then
        $txt = controllistview ("Mygame", "", "SysListView322", "GetText", $i, 4)
        if $txt = $opts Then
;~             controllistview ("Mygame", "", "SysListView322", "Select", $i)
        _GUICtrlListView_SetItemSelected($chnd, $i)
        _GUICtrlListView_ClickItem($chnd, $i)
            msgbox (0, "", "Found and selected item!")
            WinActivate ("Mygame")
            quitnow ()
        endIf
    endIf
Next
Link to comment
Share on other sites

  • 10 years later...
  • Developers
16 minutes ago, Nendlescap_Allien said:

;Use the function: 

_GUICtrlListView_EnsureVisible($idListview, $index)

 

Could you please explain what this post is supposed to do in an 11 years old thread?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 2 weeks later...

Just for the correct info:

Function _GUICtrlListView_ClickItem() which I used in my solution uses _GUICtrlListView_EnsureVisible() 

so your "smart" advice is useless.

Func _GUICtrlListView_ClickItem($hWnd, $iIndex, $sButton = "left", $fMove = False, $iClicks = 1, $iSpeed = 1)
    If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $aPos, $tRect, $iX, $iY, $tPoint, $iMode

    _GUICtrlListView_EnsureVisible($hWnd, $iIndex, False)
    $tRect = _GUICtrlListView_GetItemRectEx($hWnd, $iIndex)
    $tPoint = _WinAPI_PointFromRect($tRect, True)
    $tPoint = _WinAPI_ClientToScreen($hWnd, $tPoint)
    _WinAPI_GetXYFromPoint($tPoint, $iX, $iY)
    If Not $fMove Then
        $iMode = Opt("MouseCoordMode", 1)
        $aPos = MouseGetPos()
        Opt("MouseCoordMode", $iMode)
        _WinAPI_ShowCursor(False)
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
        MouseMove($aPos[0], $aPos[1], 0)
        _WinAPI_ShowCursor(True)
    Else
        MouseClick($sButton, $iX, $iY, $iClicks, $iSpeed)
    EndIf
EndFunc   ;==>_GUICtrlListView_ClickItem

 

Link to comment
Share on other sites

Just for the correct info:

None of those presented is useless.

 _GUICtrlListView_EnsureVisible

Is a simple and faster solution.

 

Think about it. 

In your solution with

_GUICtrlListView_ClickItem
  • How many lines of code are executed to get to the solution?
  • How many functions are called within _GUICtrlListView_ClickItem ?
  • Is it necessary to click the item first?

 

Edited by Nendlescap_Allien
Grammar Correction
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...