Jump to content

Find ID of Listview item by stringname


 Share

Recommended Posts

Hey guys

This may be quite simple, but I haven't manage to solve it yet :/

All I want to do is get the ID of Xitem, so I can click it with " _GUICtrlListView_ClickItem" .

So I need to find the item based on the that fact that I know the text/string name of that item.

 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    GUICreate("listview items", 300, 300, -1, -1)


    Local $idListview = GUICtrlCreateListView("col1", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
    Local $idButton = GUICtrlCreateButton("ID_of_Xitem?", 75, 170, 70, 20)
    Local $idItem1 = GUICtrlCreateListViewItem("Aitem", $idListview)
    Local $idItem2 = GUICtrlCreateListViewItem("Xitem", $idListview)
    Local $idItem3 = GUICtrlCreateListViewItem("Zitem", $idListview)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton

               MsgBox(0,"","ID of Xitem is ?")

               _GUICtrlListView_ClickItem($clv, ?)

        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Link to comment
Share on other sites

  • Moderators

davis1337,

Do not forget that there is a ListView UDF as well as the native functions:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Example()

Func Example()
    GUICreate("listview items", 300, 300, -1, -1)

    Local $idListview = GUICtrlCreateListView("col1", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
    Local $idButton = GUICtrlCreateButton("ID_of_Xitem?", 75, 170, 70, 20)
    Local $idItem1 = GUICtrlCreateListViewItem("Aitem", $idListview)
    Local $idItem2 = GUICtrlCreateListViewItem("Xitem", $idListview)
    Local $idItem3 = GUICtrlCreateListViewItem("Zitem", $idListview)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton
                $nID = _GUICtrlListView_FindText($idListview, "Xitem")
                MsgBox(0, "", "ID of Xitem is " & $nID)
                _GUICtrlListView_ClickItem($idListview, $nID)
        EndSwitch
    WEnd
EndFunc   ;==>Example

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

Melba23

Thanks! I can't believe there was a native function that did exactly what I wanted!

I have searched so many threads, and tried so many weird things :) No idea why I didn't find the "_GUICtrlListView_FindText" function.

Anyway, thanks again!

Edited by david1337
Link to comment
Share on other sites

  • Moderators

david1337,

_GUICtrlListView_FindText is a UDF function, not a native one - just like the one you use to click the item.

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

×
×
  • Create New...