Jump to content
Sign in to follow this  
rexx

_GUICtrlListView_SelectItem()

Recommended Posts

rexx

Is there a function works like _GUICtrlTreeView_SelectItem() but for listview?

I got _GUICtrlListView_SetItemFocused() and _GUICtrlListView_SetItemSelected() to let an item selected and focused, but the listview is not auto scroll to the item.

I know there's _GUICtrlListView_Scroll() but i don't know how much to scroll, set a big value can solve this but seems not a good solution.

any suggestions?

Thanks.

Share this post


Link to post
Share on other sites
Authenticity

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>

Global $hGUI, $hListView
Global $ListView

$hGUI = GUICreate('Title', 400, 300)
$ListView = GUICtrlCreateListView('1    |2    |3    |4    |5    |6    ', 0, 0, 400, 300)
$hListView = GUICtrlGetHandle($ListView)

_GUICtrlListView_BeginUpdate($hListView)
For $i = 1 To 3000
    GUICtrlCreateListViewItem('1    |2    |3    |4    |5    |6    ', $ListView)
Next
_GUICtrlListView_EndUpdate($hListView)

AdlibEnable('_RandomlySelectLVItem', 1000)
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

AdlibDisable()
GUIDelete()

Func _RandomlySelectLVItem()
    Local $iIndex = Random(0, _GUICtrlListView_GetItemCount($hListView)-1, 1)
    
    _GUICtrlListView_SetItemSelected($hListView, $iIndex, True, True)
    _SendMessage($hListView, $LVM_ENSUREVISIBLE, $iIndex, False)
EndFunc

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.