asilcott Posted November 7, 2013 Share Posted November 7, 2013 (edited) Longtime AutoIt fan, novice programmer and forum user. Please let me know if there is anything I should be doing differently. I am working on a program where I drag an item from a listview and drop it onto a treeview. All is well with my drag and drop, but I am stuck trying to add a feature that will automatically scroll when the user drags an item to the bottom or the top of the treeview. I can get the treeview to auto-scroll, but the last treeview item just repeats. I am sure there is an easy way to refresh the treeview during scrolling that I am just not finding. The included example doesn't have any drag and drop. Just moving your mouse to the bottom or top of the treeview will show my problem. Any help would be greatly appreciated. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> Global $iScrollUp=False Global $iScrollDown=False ;Create GUI $hWnd = GUICreate("Auto Scroll Treeview", 300, 600, (@DesktopWidth/2)-150, (@DesktopHeight/2)-300, BitOR($WS_SIZEBOX,$WS_SYSMENU,$WS_MINIMIZEBOX,$WS_MAXIMIZEBOX)) ;Create Treeview Global $iTreeView = GUICtrlCreateTreeView(0, 0, 300, 600, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_SHOWSELALWAYS,$WS_GROUP,$WS_TABSTOP), $WS_EX_CLIENTEDGE) Global $hTreeView = GUICtrlGetHandle($iTreeView) ;Initialize Scrollbar _GUIScrollBars_Init($hTreeView) ;Populate Treeview _GUICtrlTreeView_BeginUpdate($hTreeView) For $i=0 To 200 _GUICtrlTreeView_Add($hTreeView, 0, "Item" & $i,0,0) Next _GUICtrlTreeView_EndUpdate($hTreeView) GUISetState() While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MOUSEMOVE Local $tMPos = _WinAPI_GetMousePos(True, $hTreeView) If DllStructGetData($tMPos, 2) <= 30 Then ;mouse moved into upper portion of treeview, set flag to scroll up $iScrollUp=True $iScrollDown=False ElseIf DllStructGetData($tMPos, 2) >= 540 Then ;mouse moved into lower portion of treeview, set flag to scroll down $iScrollUp=False $iScrollDown=True Else ;mouse is not in either upper or lower portion of treeview, so don't move $iScrollUp=False $iScrollDown=False EndIf EndSelect If $iScrollUp Then If _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT) <> _GUIScrollBars_GetScrollInfoMin($hTreeview, $SB_VERT) Then ;Move scrollbar up 1 ;_GUIScrollBars_ScrollWindow($hTreeView, 0, 1) _GUIScrollBars_SetScrollInfoPos($hTreeview, $SB_VERT, _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT)-1) EndIf Sleep(50) EndIf If $iScrollDown Then If _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT) <> _GUIScrollBars_GetScrollInfoMax($hTreeview, $SB_VERT) Then ;Move scrollbar down 1 ;_GUIScrollBars_ScrollWindow($hTreeView, 0, -1) _GUIScrollBars_SetScrollInfoPos($hTreeview, $SB_VERT, _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT)+1) EndIf Sleep(50) EndIf WEnd Edited November 7, 2013 by asilcott Link to comment Share on other sites More sharing options...
Solution kylomas Posted November 8, 2013 Solution Share Posted November 8, 2013 (edited) asilcot, Try this, expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <GuiScrollBars.au3> #include <ScrollBarConstants.au3> Global $iScrollUp=False Global $iScrollDown=False ;Create GUI $hWnd = GUICreate("Auto Scroll Treeview", 300, 600, (@DesktopWidth/2)-150, (@DesktopHeight/2)-300, BitOR($WS_SIZEBOX,$WS_SYSMENU,$WS_MINIMIZEBOX,$WS_MAXIMIZEBOX)) ;Create Treeview Global $iTreeView = GUICtrlCreateTreeView(0, 0, 300, 600, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_SHOWSELALWAYS,$WS_GROUP,$WS_TABSTOP), $WS_EX_CLIENTEDGE) Global $hTreeView = GUICtrlGetHandle($iTreeView) ;Initialize Scrollbar _GUIScrollBars_Init($hTreeView) ;Populate Treeview _GUICtrlTreeView_BeginUpdate($hTreeView) For $i=0 To 200 _GUICtrlTreeView_Add($hTreeView, 0, "Item" & $i,0,0) Next _GUICtrlTreeView_EndUpdate($hTreeView) GUISetState() While 1 $Msg = GUIGetMsg() Select Case $Msg = $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_MOUSEMOVE Local $tMPos = _WinAPI_GetMousePos(True, $hTreeView) If DllStructGetData($tMPos, 2) <= 30 Then ;mouse moved into upper portion of treeview, set flag to scroll up $iScrollUp=True $iScrollDown=False ElseIf DllStructGetData($tMPos, 2) >= 540 Then ;mouse moved into lower portion of treeview, set flag to scroll down $iScrollUp=False $iScrollDown=True Else ;mouse is not in either upper or lower portion of treeview, so don't move $iScrollUp=False $iScrollDown=False EndIf EndSelect If $iScrollUp Then If _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT) <> _GUIScrollBars_GetScrollInfoMin($hTreeview, $SB_VERT) Then ;Move scrollbar up 1 ;_GUIScrollBars_ScrollWindow($hTreeView, 0, 1) _GUIScrollBars_SetScrollInfoPos($hTreeview, $SB_VERT, _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT)-1) _GUICtrlTreeView_EndUpdate($hTreeView) ; <------------- added to re-draw treeview EndIf ;Sleep(50) EndIf If $iScrollDown Then If _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT) <> _GUIScrollBars_GetScrollInfoMax($hTreeview, $SB_VERT) Then ;Move scrollbar down 1 ;_GUIScrollBars_ScrollWindow($hTreeView, 0, -1) _GUIScrollBars_SetScrollInfoPos($hTreeview, $SB_VERT, _GUIScrollBars_GetScrollInfoPos($hTreeview, $SB_VERT)+1) _GUICtrlTreeView_EndUpdate($hTreeView) ; <------------- added to re-draw treeview EndIf ;Sleep(50) EndIf WEnd kylomas edit: there is an interesting discussion of a related issue >here... I tried the alternate suggestions from this thread but they did not work. Maybe scrollbars are a different animal, don't know, never used them. Edited November 8, 2013 by kylomas asilcott 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
asilcott Posted November 8, 2013 Author Share Posted November 8, 2013 Ugh, this is exactly why I don't ask for help. The answer was so simple that now I look like an idiot! One other thing I added to my Treeview to make the scrolling smoother was $WS_EX_COMPOSITED. Thanks a ton for the help, kylomas. Link to comment Share on other sites More sharing options...
kylomas Posted November 8, 2013 Share Posted November 8, 2013 asilcott, Glad to help and you do NOT look like an idiot, there is a difference between stubborness and determination. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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