zackrspv Posted April 15, 2008 Share Posted April 15, 2008 (edited) How to test if a listviewItem already exists before adding it. I know how to do the guictrlread to get the value, but how do you get ALL values of the listView to ensure that you are not adding a new one? example code expandcollapse popup#include <GUIConstants.au3> $gui = GUICreate("test", 500, 500) $ListView1 = GUICtrlCreateListView("Ticket", 0, 0, 837, 396) guictrlsetstyle(-1, $LVS_LIST) $update = GuiCtrlCreateButton("Update", 0, 400, 90, 25) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows2', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows3', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows4', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows5', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows6', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows7', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows8', $ListView1) GUICtrlCreateListViewItem('JDJKAJEJJEK - Mary Joe, Unable to Open Windows9', $ListView1) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() if $nMsg = 0 Then elseif $nMsg = -11 Then Else ConsoleWrite($nMsg&@CRLF) EndIf Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $update ;- //////////////////////////// UPDATE CODE HERE /////////////////////////////////// EndSwitch WEnd ;; Insert this to handle events Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView1 Select Case $event = $NM_click ;~ msgbox(0,"",GUICtrlRead(GUICtrlRead($listview1),1)) EndSelect EndSelect endFunc Now, let's say that when I click a button, I have the following function: Func _GetTickets() $ActiveTickets = _Query($sql, "SELECT * FROM tickets WHERE active=1") With $ActiveTickets while NOT .EOF $tlcrmid = "" $tlcrmname = "" $verifyData = "" $tlcrmid = .Fields('crm_id').value $tlcrmname = .Fields('crm_name').value $tlmainissue = .Fields('main_issue').value ;- check if already in list $verifyData = Guictrlread(GuictrlRead($TicketList, 1)) if $verifyData = $tlcrmid & " - " & $tlcrmname & ": "&$tlmainissue Then Else GUICtrlCreateListViewItem($tlcrmid & " - " & $tlcrmname & ": "&$tlmainissue, $TicketList) EndIf .MoveNext WEnd EndWith EndFunc Obviously the above is incorrect, because it is only looking for a value that is SELECTED, not for the ENTIRE list view. But that's how I would structure it. How can I accomplish this check? I'm sure I could use an array, and then use ArraySearch to look for any value that matches it, and if fond then simply skip the step to add; but then I have no idea how to add that to an array. lol Ideas? Thanks! Edited April 15, 2008 by zackrspv -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë ë§§ëñ§ë øƒ !ïƒë. Link to comment Share on other sites More sharing options...
PsaltyDS Posted April 15, 2008 Share Posted April 15, 2008 How to test if a listviewItem already exists before adding it. I know how to do the guictrlread to get the value, but how do you get ALL values of the listView to ensure that you are not adding a new one? One method: If ControlListView( $gui, "", $ListView1, "FindItem" , "Old Item Text") = -1 Then MsgBox(64, "OK", "That item does not already exists.") Else MsgBox(16, "Error", "That item already exists!") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
zackrspv Posted April 15, 2008 Author Share Posted April 15, 2008 worked like a charm! Awesome, thanks so much -_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë ë§§ëñ§ë øƒ !ïƒë. Link to comment Share on other sites More sharing options...
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