WeMartiansAreFriendly Posted September 12, 2008 Share Posted September 12, 2008 (edited) After several attempts at scrolling a listview item with _GUICtrlListView_Scroll, I've finally came up with a very simple solution thanks to this discussion.Update* $iItemIndex is now optional if set to -1 the last item will be scrolledexpandcollapse popup#include <GuiListView.au3> ;--------------------------------------------------------------------- ; Example ;--------------------------------------------------------------------- #include <GuiConstantsEx.au3> Local $hListView GUICreate("ListView Scroll", 400, 300) $hListView = GUICtrlCreateListView("Auto Scroll Example", 2, 2, 394, 268) GUISetState() For $i = 0 To 100 GUICtrlCreateListViewItem("Item " & $i, $hListView) Next Sleep(1000) For $i = 0 To _GUICtrlListView_GetItemCount($hListView) -1 Step 1 ; Scroll to NEXT item _GUICtrlListView_ScrollItem($hListView, $i) ; do some stuff _GUICtrlListView_SetItemSelected($hListView, $i, True) _GUICtrlListView_SetItemText($hListView, $i, "GOTCHA! "& $i) Sleep(100) ;... ect Next While GUIGetMsg() <> -3 WEnd ;--------------------------------------------------------------------- ;#FUNCTION#============================================================================================================= ; Name...........: _GUICtrlListView_ScrollItem() ; Description ...: Scrolls a listview item ; Syntax.........: _GUICtrlListView_ScrollItem($hListView, $iItemIndex, $iIncrement) ; Parameters ....: $hListView - Handle to the control ; $iItemIndex - [optional] The zero-based index of the item, if set to -1 the last item will be used. ; $fPartialOK - [optional] Value specifying whether the item must be entirely visible ; $iIncrement - [optional] Value of type int that specifies the amount of horizontal scrolling in pixels. ; Return values .: Success - True ; Failure - False ; Author ........: mrRevoked ; Remarks .......: ; Related .......: _GUICtrlListView_Scroll() ; Link ..........; ; Example .......; Yes ; ===================================================================================================================== Func _GUICtrlListView_ScrollItem($hListView, $iItemIndex=-1, $fPartialOK = False, $iIncrement = 16) Local $iSuccess1, $iSuccess2 If $iItemIndex = -1 Then $iItemIndex = _GUICtrlListView_GetItemCount($hListView)-1 $iSuccess1 = _GUICtrlListView_Scroll($hListView, 0, $iIncrement) $iSuccess2 = _GUICtrlListView_EnsureVisible($hListView, $iItemIndex, $fPartialOK) Return $iSuccess1 And $iSuccess2 EndFunc Edited October 4, 2008 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
WeMartiansAreFriendly Posted September 26, 2008 Author Share Posted September 26, 2008 (edited) Here's another function, _GUICtrlListView_CreateItem (modified from the help file) works very similar to GUICtrlCreateListViewItem.UpdateFixed: Incompatibility with _GUICtrlListView_RegisterSortCallBack (application defined data was always 0)expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $Form2 = GUICreate("Example", 413, 298, 303, 219) $ListView = GUICtrlCreateListView("Test1|Test2", 8, 16, 394, 206) $Button1 = GUICtrlCreateButton("Create", 16, 232, 75, 25, 0) $Button2 = GUICtrlCreateButton("Delete All", 176, 232, 171, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $timer = TimerInit() For $i = 1 to 1200 _GUICtrlListView_CreateItem($ListView, "Test1" & $i &"|"& "Test2"& $i) Next ConsoleWrite("creation speed: :" & TimerDiff($timer) &@lf) Case $Button2 $hListView = GUICtrlGetHandle($ListView) ; get the handle to the list view $timer = TimerInit() _GUICtrlListView_DeleteAllItems($hListView) ConsoleWrite("deletion speed: :" & TimerDiff($timer) &@lf) EndSwitch WEnd ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlListView_CreateItem() ; Description ...: Creates a list view item with subitems ; Syntax.........: _GUICtrlListView_CreateItem($hListView, $sItem) ; Parameters ....: $hListView - Handle to the control ; $sItemText - Item text (string delimited) ; Return values .: Success - Item Index ; Failure @error ; 1 - Item delimiter failed ; 2 - Failed to Add item ; 3 - Failed to Add sub item ; Author ........: mrRevoked ; Remarks .......: ; Related .......: _GUICtrlListView_AddItem, _GUICtrlListView_AddSubItem ; Link ..........; ; Example .......; Yes ; ==================================================================================================== Func _GUICtrlListView_CreateItem($hListView, $sItemText) Local $sDelim = Opt('GUIDataSeparatorChar') Local $aItem = StringSplit($sItemText, $sDelim) If $aItem[0] < 1 Then Return SetError(1, 0, 0) Local $iCount = _GUICtrlListView_GetItemCount($hListView) Local $iIndex = _GUICtrlListView_AddItem($hListView, $aItem[1], -1, $iCount + 1) If $iIndex < 0 Then Return SetError(2, 0, 0) For $i = 2 To $aItem[0] $iSubItem = _GUICtrlListView_AddSubItem($hListView, $iIndex, $aItem[$i], $i - 1) If $iSubItem = False Then Return SetError(3, 0, 0) ; don't want to be stuck inside a loop of fail. Next Return $iIndex EndFunc ;_GUICtrlListView_CreateItem Edited October 4, 2008 by mrRevoked Don't bother, It's inside your monitor!------GUISetOnEvent should behave more like HotKeySet() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now