david1337

Find ID of Listview item by stringname

7 posts in this topic

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

 

Share this post


Link to post
Share on other sites



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

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

david1337,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Oh yeah sorry, what I meant was: can't believe that the "normal" GuiListView UDF had this function.
Anything that is not your GUIListViewEx UDF, is native to me :lol:

Edited by david1337

Share this post


Link to post
Share on other sites

Hi kylomas

Thanks for the warning!
It's fine in my case though, as there can't be two identical items in my list.

- David
 

Share this post


Link to post
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

  • Similar Content

    • rootx
      Listview subitem persistent focus?
      By rootx
      Holà, I would like to understand why when I select a subitem remains the focus on it. THX
      ;Rootx #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <GuiImageList.au3> #include <MsgBoxConstants.au3> #include <GuiListView.au3> Global $idListview #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 450, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 16, 16, 75, 25) $idListview = GUICtrlCreateListView("", 16, 56, 586, 358, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SORTASCENDING,$LVS_AUTOARRANGE), BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES)) _GUICtrlListView_InsertColumn($idListview, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($idListview, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($idListview, 2, "Column 3", 100) _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1, 1) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2, 1) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1, 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 3", 2,1) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2) _GUICtrlListView_AddSubItem($idListview, 2, "Row 3: Col 2",1, 1) _GUICtrlListView_AddSubItem($idListview, 2, "Row 3: Col 3",2, 1) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iCol = DllStructGetData($tInfo, "SubItem") ConsoleWrite("Column clicked: " & $iCol & @CRLF) Case $NM_CLICK $aHit = _GUICtrlListView_SubItemHitTest($hWndFrom) $LVEIP_Item = $aHit[0] $LVEIP_SubItem = $aHit[1] Local $tItem $tItem = DllStructCreate($tagLVITEM) DllStructSetData($tItem, "Mask", $LVIF_STATE) DllStructSetData($tItem, "Item", $LVEIP_Item) DllStructSetData($tItem, "SubItem", $LVEIP_SubItem) DllStructSetData($tItem, "State", $LVIS_SELECTED) DllStructSetData($tItem, "StateMask", $LVIS_SELECTED) _GUICtrlListView_SetItemEx($hWndFrom, $tItem) ConsoleWrite("Selected Cell " & _GUICtrlListView_GetItemText($idListview,$LVEIP_Item,$LVEIP_SubItem)&@CRLF) EndSwitch EndSwitch EndFunc  
    • skybax
      Array to Listview
      By skybax
      Good morning all,
      I have a question regarding a situation im in...
       
      I have an array with information from sql query, how can i send this information to a listview ?
       
      $citeste_daune = "SELECT `id_dauna`,`data_incident`,`sala`,`autor`,`suma` FROM `daune` WHERE `status`=1;" $sa_citit_daune = _query($sqlinstance, $citeste_daune) Global $aresult[10001][5] = [[10000, 5]] Global $iindex = 0 With $sa_citit_daune While NOT .eof $aresult[$iindex][0] = .fields("id_dauna").value $aresult[$iindex][1] = .fields("data_incident").value $aresult[$iindex][2] = .fields("sala").value $aresult[$iindex][3] = .fields("autor").value $aresult[$iindex][4] = .fields("suma").value $iindex = $iindex + 1 .movenext WEnd EndWith ReDim $aresult[$iindex][5] $aresult[0][0] = $iindex - 1 _ArrayDisplay($aresult) GUICtrlCreateListViewItem(_ArrayToString($aresult), $lista_daune_active)  
      This is what i see when i execure _ArrayDisplay($aresult)

    • 31290
      convert array index to proper value
      By 31290
      Hi guys,
      I'm facing a problem that I can't solve, despite trying hard.
      I have an .ini file with several sections:
      [Latitude E5440] URL=http://downloads.dell.com/published/pages/latitude-e5440-laptop.html [Latitude E5450] URL=http://downloads.dell.com/published/pages/latitude-e5450-laptop.html [Latitude E5470] URL=http://downloads.dell.com/published/pages/latitude-e5470-laptop.html [Latitude E7240] URL=http://downloads.dell.com/published/pages/latitude-e7240-ultrabook.html [Latitude E7250] URL=http://downloads.dell.com/published/pages/latitude-e7250-ultrabook.html [Latitude E7270] URL=http://downloads.dell.com/published/pages/latitude-e7270-ultrabook.html Then I collect the computer model name and try to look if it exists in the ini file. But, when performing the search, I only got the index in the array.
      For example, my computer model is a "Latitude E7240". An "_ArraySearch" gives me "4" as a result and because this is also the fourth place of my search in the ini file. It works well if I move the section anywhere else in the file and always give me the correct position.
      Question is: How can I convert the index number to the section name so I can tell my script that if it's found in the ini file, the download URL variable will be set to the corresponding key in the ini file.
      Here's my code so far:
      Can someone give me an hand on this?
      Thanks
      -31290-
    • crushyna
      Error while adding file names to ListView
      By crushyna
      Hello everyone!

      I've encountered a strange problem while adding files (or rather file names) to a ListView.
      Mechanics are simple:
      1. Select files to add (FileOpenDialog + Multiselect)
      2. Split selected string (filepath) into array (StringSplit)
      3. File names appear on ListView (GUICtrlCreateListViewItem)

      Writing starts from second array (since 0 is array size, and 1 is filepath).
      Problem occurs when I try to add one file. Then, no filenames are added.
      As far as I know, selecting one file generates only 2 strings (0 and 1) to split, therefore no string is written into ListView.
       
      Is there any way / workaround to make this thing work properly?

      Some code here:
      While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idAddTest $sMessage = "Select test cases to load:" $sFileOpenDialog = FileOpenDialog($sMessage, @WorkingDir & "\data\tests\", "All (*.*)", $FD_FILEMUSTEXIST & $FD_MULTISELECT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "No test(s) were selected.") FileChangeDir(@ScriptDir) Else FileChangeDir(@ScriptDir) $aFileList = StringSplit($sFileOpenDialog, "|", @CRLF) For $i = 2 to $aFileList[0] MsgBox( 0, "test", $aFileList[$i]) ;just for testing purposes GUICtrlCreateListViewItem($aFileList[$i], $idTestCaseList) Next EndIf EndSwitch WEnd  
      And nothing more spectacular from ListView side:
      Global $idTestCaseList = GUICtrlCreateListView("List of Tests ", 24, 24, 225, 502, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) GUICtrlSetTip(-1, "List of test cases."& @CRLF &"Hold CTRL to select multiple lines.")  
      Any help appreciated!
    • Muhammad_Awais_Sharif
      String split into char
      By Muhammad_Awais_Sharif
      How To split string into Array of char ?