Jump to content

Listview Items


Zohran
 Share

Recommended Posts

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

Zohran,

Why did you not say that your ListView was in icon view? Am I supposed to be mind reader as well? :huh:

Give me a while and I will see what I can come up with. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Zohran,

That was harder than I thought it would be - this is as far as I have got: :sweating:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Zohran,

That was harder than I thought it would be - this is as far as I have got: :sweating:

#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 by Zohran
Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Zohran,

:sweating:

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. :)

M23

Edit: 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? :huh:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...