Zohran Posted November 3, 2012 Posted November 3, 2012 Hi. How to get indices of items in a listview which are currently visible on the screen, not all items?
Moderators Melba23 Posted November 3, 2012 Moderators Posted November 3, 2012 Zohran, I would do it like this: #include <GUIConstantsEx.au3> #include <GuiListView.au3> $hGUI = GUICreate("Test", 500, 500) $cLV = GUICtrlCreateListView("Item|SubItem", 10, 10, 480, 105) _GUICtrlListView_SetColumnWidth($cLV, 0, 200) _GUICtrlListView_SetColumnWidth($cLV, 1, 250) For $i = 0 To 30 GUICtrlCreateListViewItem("Item " & $i & "|SubItem " & $i, $cLV) Next ; Find out how many items will fit vertically $iCount = _GUICtrlListView_GetCounterPage($cLV) $cButton = GUICtrlCreateButton("Visible?", 10, 300, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton ; Find the top index $iTop = _GUICtrlListView_GetTopIndex($cLV) ; And so the bottom must be $iBottom = $iTop + $iCount - 1 ; And announce the result MsgBox(0, "Visible", "Items " & $iTop & " to " & $iBottom) EndSwitch WEnd All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Zohran Posted November 3, 2012 Author Posted November 3, 2012 Zohran, I would do it like this: #include <GUIConstantsEx.au3> #include <GuiListView.au3> $hGUI = GUICreate("Test", 500, 500) $cLV = GUICtrlCreateListView("Item|SubItem", 10, 10, 480, 105) _GUICtrlListView_SetColumnWidth($cLV, 0, 200) _GUICtrlListView_SetColumnWidth($cLV, 1, 250) For $i = 0 To 30 GUICtrlCreateListViewItem("Item " & $i & "|SubItem " & $i, $cLV) Next ; Find out how many items will fit vertically $iCount = _GUICtrlListView_GetCounterPage($cLV) $cButton = GUICtrlCreateButton("Visible?", 10, 300, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton ; Find the top index $iTop = _GUICtrlListView_GetTopIndex($cLV) ; And so the bottom must be $iBottom = $iTop + $iCount - 1 ; And announce the result MsgBox(0, "Visible", "Items " & $iTop & " to " & $iBottom) EndSwitch WEnd All clear? M23 Dear Melba It is not working for icon view.
Moderators Melba23 Posted November 3, 2012 Moderators Posted November 3, 2012 Zohran, Why did you not say that your ListView was in icon view? Am I supposed to be mind reader as well? Give me a while and I will see what I can come up with. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Zohran Posted November 3, 2012 Author Posted November 3, 2012 Zohran,Why did you not say that your ListView was in icon view? Am I supposed to be mind reader as well? Give me a while and I will see what I can come up with. M23oops, sorry my mistake
Moderators Melba23 Posted November 3, 2012 Moderators Posted November 3, 2012 Zohran, That was harder than I thought it would be - this is as far as I have got: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> $hGUI = GUICreate("LV", 400, 300) $iLV_Width = 380 $iLV_Ht = 230 $iSpace_H = 50 $iSpace_V = 25 $cLV = GUICtrlCreateListView("", 10, 10, $iLV_Width, $iLV_Ht, BitOR($LVS_ICON, $LVS_ALIGNLEFT)) _GUICtrlListView_SetView($cLV, 1) $hImageList = _GUIImageList_Create(32, 32, 5, 4, 3) _GUIImageList_AddIcon($hImageList, @SystemDir & "shell32.dll", 110, True) _GUIImageList_AddIcon($hImageList, @SystemDir & "shell32.dll", 131, True) _GUIImageList_AddIcon($hImageList, @SystemDir & "shell32.dll", 165, True) _GUICtrlListView_SetImageList($cLV, $hImageList, 0) _GUICtrlListView_SetIconSpacing($cLV, $iSpace_H, $iSpace_V) $cButton = GUICtrlCreateButton("Visible?", 10, 250, 80, 30) ; Add items For $i = 0 To 49 _GUICtrlListView_AddItem($cLV, "Icon " & $i, Random(0, 2, 1)) Next $iTopLeft = _GUICtrlListView_FindNearest($cLV, 25, 25) $iBotLeft = _GUICtrlListView_FindNearest($cLV, 25, $iLV_Ht - 25, 2) $iTopRt = _GUICtrlListView_FindNearest($cLV, $iLV_Width, 0, 0) $iDown = $iBotLeft - $iTopLeft + 1 $iAcross = Int($iTopRt / $iDown) $iNumVis = $iAcross * $iDown GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUIImageList_Destroy($hImageList) Exit Case $cButton $iTopLeft = _GUICtrlListView_FindNearest($cLV, $iSpace_H / 2, $iSpace_V / 2) $iEnd = $iTopLeft + $iNumVis - 1 MsgBox(0, "Visible", "Items " & $iTopLeft & " to " & $iEnd) EndSwitch WEnd I will see if I can come up with something better. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Zohran Posted November 3, 2012 Author Posted November 3, 2012 (edited) Zohran, That was harder than I thought it would be - this is as far as I have got: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> $hGUI = GUICreate("LV", 400, 300) $iLV_Width = 380 $iLV_Ht = 230 $iSpace_H = 50 $iSpace_V = 25 $cLV = GUICtrlCreateListView("", 10, 10, $iLV_Width, $iLV_Ht, BitOR($LVS_ICON, $LVS_ALIGNLEFT)) _GUICtrlListView_SetView($cLV, 1) $hImageList = _GUIImageList_Create(32, 32, 5, 4, 3) _GUIImageList_AddIcon($hImageList, @SystemDir & "shell32.dll", 110, True) _GUIImageList_AddIcon($hImageList, @SystemDir & "shell32.dll", 131, True) _GUIImageList_AddIcon($hImageList, @SystemDir & "shell32.dll", 165, True) _GUICtrlListView_SetImageList($cLV, $hImageList, 0) _GUICtrlListView_SetIconSpacing($cLV, $iSpace_H, $iSpace_V) $cButton = GUICtrlCreateButton("Visible?", 10, 250, 80, 30) ; Add items For $i = 0 To 49 _GUICtrlListView_AddItem($cLV, "Icon " & $i, Random(0, 2, 1)) Next $iTopLeft = _GUICtrlListView_FindNearest($cLV, 25, 25) $iBotLeft = _GUICtrlListView_FindNearest($cLV, 25, $iLV_Ht - 25, 2) $iTopRt = _GUICtrlListView_FindNearest($cLV, $iLV_Width, 0, 0) $iDown = $iBotLeft - $iTopLeft + 1 $iAcross = Int($iTopRt / $iDown) $iNumVis = $iAcross * $iDown GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _GUIImageList_Destroy($hImageList) Exit Case $cButton $iTopLeft = _GUICtrlListView_FindNearest($cLV, $iSpace_H / 2, $iSpace_V / 2) $iEnd = $iTopLeft + $iNumVis - 1 MsgBox(0, "Visible", "Items " & $iTopLeft & " to " & $iEnd) EndSwitch WEnd I will see if I can come up with something better. M23 thank you. Not very accurate.Its a good effort. Edited November 3, 2012 by Zohran
Moderators Melba23 Posted November 3, 2012 Moderators Posted November 3, 2012 Zohran,You are welcome - I will look again at the code after dinner. But I know what I wrote - in future could you please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button. Requoting the previous post just pads the thread unneccessarily. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
trancexx Posted November 3, 2012 Posted November 3, 2012 No. He's not. If you are replying to a specific post then use the quote buton. ♡♡♡ . eMyvnE
Moderators Melba23 Posted November 3, 2012 Moderators Posted November 3, 2012 (edited) Zohran,This is confusing.I quite agree, but trancexx is entitled to her opinion - and in this matter, as in so many others, she and I have opposing views. You will have to decide for yourself which of us is correct - but there is no need to state it here. M23Edit: Just seen your "not very accurate" comment concerning the code I posted earlier - I realise that and I will see what I can do to improve it. Does the ListView at least look like the one you want to use? Edited November 3, 2012 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted November 4, 2012 Moderators Posted November 4, 2012 Zohran,Further testing has shown the _GUICtrlListView_FindNearest to be very inaccurate - it is extremely sensitive to very snall changes of position within the ListView and you often get a result you do not expect. I will have a think about another approach. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Zohran Posted November 4, 2012 Author Posted November 4, 2012 Hmmmm. Well i want this function because i am going to update my advanced icon displayer.Because if load icons of size 128x128 or greater size for items greater than 500 it consumes much memory.
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