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

David1337,

Please note, _GUICtrlListView_FindText finds the first occurrence of the search text.

kylomas

1 person likes this

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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

    • Clemens
      By Clemens
      Hi there,
      I have a small hopefully quick fixable issue with reading information from my ListView:
      So in fact I just want to have information about which items are selected, so I'm using
      msgbox(0 , "return", GUICtrlRead($myListView), 1)
      but unfortunately it only returns me either the first item id or if this is not selected the second item id, or if this is not selected the third, etc. or 0 if none is selected.
      Anybody has an idea how to get the full picture of my >>multiple Items selected<< ListView?
      Thanks in advance!
      Clemens
    • SkysLastChance
      By SkysLastChance
      Okay so I am not sure if I can do this or not with the code I currently have but, I would like to send lastname and the first name with a comma inbetween. 
      so it would look like "last name,first name" 
      right now I just have it sending the last name.
      any help or sugestions are appreciated. 
       
      $r = 1 Local $aArray = _Excel_RangeRead($oExcel, Default, Default) For $i = 1 To UBound($aArray) - 1 ;$i =0 Start from row A $sR1 = $aArray[$i][0] ;status $sR2 = $aArray[$i][1] ;first name $sR3 = $aArray[$i][2] ;Last name $sR5 = $aArray[$i][5] ;Email Address WinWaitActive ("[CLASS:MGUIWin]") Sleep (100) ControlSend("[CLASS:MGUIWin]", "", "Edit2", $sR3, & @CR) $r = $r + 1 If $r > $sBox Then Exit Endif Next  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Hi guys! How are you? Hope you're fine
      I'm trying to use SQLite for managing some data, and, I would like to display my "retrieved" data, but I'm trying to do a select from 2 table, and seems to not work properly...
      What I'd like to do is retrieve data from 2 tables and display in a listview...
      I tried with:
      Local $aRisultato, $iRighe, $iColonne, $iRVal $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell, Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then ;_SQLite_Display2DResult($aRisultato) _ArrayDisplay($aRisultato) EndIf ... but it displays a single record 41 times, and it does this thing for every record in the database...
      What do you need to help me?
      Thanks  

      EDIT:
      Managed with a double If and double query like this:
       
      $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Rockwell;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then Local $aRisultatoRockwell = $aRisultato $iRval = _SQLite_GetTable2d($hDatabase, "SELECT * FROM Magazzino_Siemens;", $aRisultato, $iRighe, $iColonne) If $iRVal = $SQLITE_OK Then _ArrayConcatenate($aRisultato, $aRisultatoRockwell) Local $i, $sRiga, $s_LV_Item For $i = 1 To Ubound($aRisultato) - 1 $sRiga = $aRisultato[$i][0] & "|" & _ $aRisultato[$i][1] & "|" & _ $aRisultato[$i][2] & "|" & _ $aRisultato[$i][3] & "|" & _ $aRisultato[$i][4] & "|" & _ $aRisultato[$i][5] & "|" & _ $aRisultato[$i][6] & "|" & _ $aRisultato[$i][7] & "|" & _ $aRisultato[$i][8] & "|" & _ $aRisultato[$i][9] & "|" & _ $aRisultato[$i][10] & "|" & _ $aRisultato[$i][11] $s_LV_Item = GUICtrlCreateListViewItem($sRiga, $lv_Lista) Next And so, the listview is created
      If anyone has another more efficient way, I'm here Thanks guys  
       
    • rootx
      By rootx
      How can I change dynamically the background colors of the selected Item? THX
      I try with...
      #include <ListBoxConstants.au3> #include <GuiListBox.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> Global $hListView #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124) GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES) GUISetBkColor(0x00E0FFFF) ; will change background color $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING) _GUICtrlListView_SetBkColor($idListview, 0xff0000) _GUICtrlListView_SetTextBkColor($idListview, 0xff0000) _GUICtrlListView_SetTextColor($idListview, 0x0000FF00) $idButton = GUICtrlCreateButton("Value?", 75, 170, 70, 20) $idItem1 = GUICtrlCreateListViewItem("item1|col22|col23", $idListview) $idItem2 = GUICtrlCreateListViewItem("item2|col12|col13", $idListview) $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview) $idItem4 = GUICtrlCreateListViewItem("item4|col32|col33", $idListview) $idItem5 = GUICtrlCreateListViewItem("item5|col32|col33", $idListview) $idItem9 = GUICtrlCreateListViewItem("item6|col32|col33", $idListview) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $idListview If Not IsHWnd($idListview) Then $hWndListView = GUICtrlGetHandle($idListview) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $Index = DllStructGetData($tInfo, "Index") $ctrlID = _GUICtrlListView_GetItemParam($idListview,$Index) Local $iItemText = _GUICtrlListView_GetItemText($idListview, DllStructGetData($tInfo, "Index"), 0) ConsoleWrite($iItemText&@CRLF) _GUICtrlListView_SetTextBkColor($idListview, 0x2E8B57) ;If BitAND(GUICtrlRead($idListview), $GUI_CHECKED) Then ; GUICtrlSetBkColor($ctrlID, 0xff0000) ;Else ; GUICtrlSetBkColor($ctrlID, 0xffff00) ;EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIF  
    • Wingens
      By Wingens
      Hi,
       
      I am trying to create a list view wich shows the content of an ini file. There is a pulldown menu wich allows me to check a certain status in the ini file if the status is found it should read out the key and in every section the same key is located after that it should fill out the listview with all results found.
       
      $OVERZICHTGUI = GUICreate("RMA Overzicht", 1235, 742, -1, -1) GUICtrlCreateLabel("Ingelogd als: " & $NAAMMEDEWERKER, 8, 0) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", 8, 16, 185, 89) GUICtrlCreateLabel("Status:", 32, 40, 37, 17) $STATUS = GUICtrlCreateCombo("", 32, 64, 140, 25,BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL)) GUICtrlSetData($STATUS, "Aangevraagd|Verzonden|Afgehandeld", "") GUICtrlCreateGroup("", -99, -99, 1, 1) $View = GUICtrlCreateListView("RMANR|RMANRLEV|DEBITNR|KLANT|STATUS|MODEL|SERIENR|AANGEMELDDOOR|AANMELDDATUM|VERZENDDATUM|RETOURDATUM|KLACHT|OPLOSSING", 8, 120, 1218, 614) $Exit = GUICtrlCreateButton("Hoofdmenu", 1104, 8, 123, 33) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $EXIT $YesOrNo = msgBox(4,"","Terug naar het hoofdmenu?") If $YesOrNo = 6 then GUIDelete($OVERZICHTGUI) MAINMENU() ExitLoop EndIf Case $STATUS $GO = 1 $STATE = GUICtrlRead($STATUS) Local $aArray = IniReadSection(@ScriptDir & "\DB\rma.ini", "STATUS") _ArrayDisplay($aArray, "Gevonden") $FOUNDRMANR = _ArraySearch($aArray, $STATE) MsgBox(4096, "", $FOUNDRMANR) If $FOUNDRMANR = -1 Then MsgBox(4096, "Not Found", "No RMA requests with this status found.") $GO = 0 EndIf If $GO = 1 Then $VAR = IniRead(@ScriptDir & "\DB\rma.ini", "RMANR", $FOUNDRMANR, "Not found") MsgBox(4096, "", $VAR) EndIf EndSwitch WEnd  
      rma-forum.ini