Jump to content

ListViewItem


Recommended Posts

How do I delete duplicate links in ListView?

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author:      myName
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <String.au3>
#include <Array.au3>
#include <GuiListView.au3>
#NoTrayIcon
$Form1 = GUICreate("", 721, 650, -1, -1)
GUISetBkColor(0xB9D1EA)
$Button1 = GUICtrlCreateButton("Select List", 2, 2, 211, 25, $WS_BORDER)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetCursor (-1, 0)
$Label1 = GUICtrlCreateLabel("", 216, 8, 400, 17, $WS_BORDER)
$Input0 = GUICtrlCreateInput("1", 630, 4, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER,$WS_BORDER))
GUICtrlSetTip($Input0, "Insert line")
$Label2 = GUICtrlCreateLabel("Start Page:", 8, 30, 78, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("1", 87, 28, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER,$WS_BORDER))
$Label3 = GUICtrlCreateLabel("Stop Page", 176, 30, 127, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("10", 304, 28, 89, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER,$WS_BORDER))
$Label4 = GUICtrlCreateLabel("Total Link:", 396, 30, 125, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("", 524, 30, 191, 17, $WS_BORDER)
$Progress1 = GUICtrlCreateProgress(104, 53, 598, 12)
$Button2 = GUICtrlCreateButton("Start", 8, 47, 75, 22, $WS_BORDER)
GUICtrlSetFont(-1, 11, 800, 0, "Arial Narrow")
GUICtrlSetCursor (-1, 0)
$ListView1 = GUICtrlCreateListView("All Links", 4, 72, 713, 572)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 700)
GUICtrlSetCursor (-1, 2)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$adauga_fisier = FileOpenDialog("Select", @DesktopDir& "", "Fisier Txt (*.txt)", 1)
If Not @error Then
     GUICtrlSetData($Label1,$adauga_fisier)
EndIf
Case $Button2
If GUICtrlRead($Label1) = "" Then
MsgBox(8240,"Warning","No File .txt !")
ElseIf GUICtrlRead($Input1) = "" Or GUICtrlRead($Input1) = 0 Then
MsgBox(8240,"Warning","No first page !")
ElseIf GUICtrlRead($Input2) = "" Or GUICtrlRead($Input2) = 0 Then
MsgBox(8240,"Warning","No page !")
ElseIf Not GUICtrlRead($Label1) = "" Then
$atentionare_start = MsgBox(8228,"Info","Please Wait...")
If $atentionare_start = 6 Then
     ;Functii extragere
     $linia_fisier = FileOpen(GUICtrlRead($Label1), 0)
     If Not @error Then
     $cuvant_linie = FileReadLine($linia_fisier,GUICtrlRead($Input0))
     FileClose($linia_fisier)
     EndIf
     For $de_la_pagina = GUICtrlRead($Input1) To GUICtrlRead($Input2)
     GUICtrlSetData($Input1,$de_la_pagina)
     $link_generat = "http://en.search.wordpress.com/?q="&$cuvant_linie&"&t=comment&s=date&page="&GUICtrlRead($Input1)
     ;http://en.search.wordpress.com/?q=work&t=comment&s=date&page=20
     $link =_IECreate($link_generat&"/",Default,0,1,0)
     _IELoadWait($link)
     Global $SourceText = _IEBodyReadHTML($link)
     _IEQuit($link)
     $string1 = _StringBetween($SourceText,'class=post-title href="','">')
     If IsArray($string1) Then
     $arry_unic = _ArrayUnique($string1)
     For $1 = 1 To UBound($arry_unic)-1
     GUICtrlSetData($Progress1,Random(80,100))
     GUICtrlCreateListViewItem($arry_unic[$1], $ListView1)
     GUICtrlSetData($Label5,$1*GUICtrlRead($Input1))
     Next

     EndIf
     Next

     MsgBox(8256,"Info","Finish")
     $salvare = FileSaveDialog("Save...",@DesktopDir,"Text files (*.txt)","",GUICtrlRead($Input2)&" Pages - "&"Nr. Links - "&GUICtrlRead($Label5)&".txt")
     If Not @error Then
     Local $deschide_salvare = FileOpen($salvare, 1)
     For $i = 0 To _GUICtrlListView_GetItemCount($ListView1)-1
     FileWrite($deschide_salvare,_GUICtrlListView_GetItemTextString($ListView1,$i)&@CRLF)
     Next
     EndIf
EndIf
EndIf
EndSwitch
WEnd

Thanks !

Edited by incepator
Link to comment
Share on other sites

You'd have to search for and delete them, or don't put them into the listview in the first place by making sure that each entry is unique.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You'd have to loop through all items in your listview, starting with the first item, get it's text and then use something like _GUICtrlListView_FindInText to see if that text matches any other items in your listview, if there's a match, delete the duplicate and continue searching. Then go to the second item in your listview and repeat.

The easier way would be to not put duplicates into the listview in the first place by making sure that each item is unique before adding it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

When I create ListView items, I usually add them to an array, so I can easily delete/modify them by simply doing GUICtrlSetData( $listview[number], "|||5th row data" ) or GUICtrlDelete( $listview[number] ) You could get the text easily with GUICtrlRead and compare it.

But then again, I'm not that knowledgeable about AutoIt as I would like to be yet.

But honestly I would do exactly what BrewManNH said. Find the culprit that makes duplicates. That would be best practice. (unless the duplicates are intentional, and adding/removing them are something supposed to happen)

Edited by caleb41610
Link to comment
Share on other sites

If you created the list view items in an array like I do myself, then you can compare them easily like this, and delete duplicates.

I didn't test it but this should work...

For $i = 1 To $array[0]
For $j = $array[0] To 1 Step -1
If $i = $j Then ContinueLoop
If $array[$i] = $array[$j] Then
GUICtrlDelete( $array[$j] )
EndIf
Next
Next
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...