funkey Posted April 15, 2010 Share Posted April 15, 2010 While working with my CSV-Editor I needed a function to ensure visible items AND subItems. So I made this funktion. I hope someone will need this. Function Func _GUICtrlListView_EnsureVisibleEx($hwnd, $iIndex, $iSubItem = 0, $fPartialOK = False) ;funkey April 15, 2010 If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) _SendMessage($hWnd, $LVM_ENSUREVISIBLE, $iIndex, $fPartialOK) Local $aRect = _GUICtrlListView_GetItemRect($hWnd, $iSubItem) Local $iPixel For $i = 0 To $iSubItem - 2 ; 2 means: show at second visible column $iPixel += _GUICtrlListView_GetColumnWidth($hWnd, $i) Next _GUICtrlListView_Scroll($hWnd, $iPixel + $aRect[0], 0) EndFunc Test-Code expandcollapse popup#include <GuiListView.au3> GUICreate("Test _GUICtrlListView_EnsureVisibleEx", 600, 600) Local $sHeader For $i = 1 To 50 $sHeader &= "|Col" & $i Next $sHeader = "Col0" & $sHeader Global $hLV = GUICtrlCreateListView($sHeader, 5, 5, 590, 590) Local $sItem For $i = 1 To 1000 For $j = 0 To 50 $sItem &= Random(1, 1000, 1) & "|" Next GUICtrlCreateListViewItem($sItem, $hLV) $sItem = "" Next AdlibRegister("_Test_GUICtrlListView_EnsureVisibleEx", 4000) _Test_GUICtrlListView_EnsureVisibleEx() GUISetState() Do Until GUIGetMsg() = -3 Func _GUICtrlListView_EnsureVisibleEx($hwnd, $iIndex, $iSubItem = 0, $fPartialOK = False) ;funkey April 15, 2010 If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) _SendMessage($hWnd, $LVM_ENSUREVISIBLE, $iIndex, $fPartialOK) Local $aRect = _GUICtrlListView_GetItemRect($hWnd, $iSubItem) Local $iPixel For $i = 0 To $iSubItem - 2 ; 2 means: show at second visible column $iPixel += _GUICtrlListView_GetColumnWidth($hWnd, $i) Next _GUICtrlListView_Scroll($hWnd, $iPixel + $aRect[0], 0) EndFunc Func _Test_GUICtrlListView_EnsureVisibleEx() Local $iItem = Random(1, 1000, 1) Local $iSubItem = Random(0, 50, 1) Local $sText = _GUICtrlListView_GetItemText($hLV, $iItem, $iSubItem) ToolTip(StringFormat("EnsureVisible %i/%i - %s", $iItem, $iSubItem, $sText)) _GUICtrlListView_EnsureVisibleEx($hLV, $iItem, $iSubItem) _GUICtrlListView_SetItemSelected($hLV, $iItem) _GUICtrlListView_SetSelectedColumn($hLV, $iSubItem) EndFunc Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
ZwinnyRolnik Posted July 23, 2010 Share Posted July 23, 2010 thx for that 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