Sign in to follow this  
Followers 0
StungStang

How do I Check for Duplicate Items in a ListView

4 posts in this topic

I have an application when i can add a data from ListView...now I want to check to make sure that I don't duplicate a field when I add an item to the ListView. How do I do that?

In simply word i dont want to add an item if it already exist =P

For example with C# this is possible with ListView.ContainsKey...there is a way to do it in autoit?

Hi!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Where are the values before you put it to a LV? In an array?

If yes, then you can make the array unique before you put it to a LV!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

It's simple...i add the value with InputBox...i read the imputbox and i do a GUICtrlCreateListViewItem.

hi!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this:

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("Test", 217, 266, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP))
$Input = GUICtrlCreateInput("", 8, 8, 121, 21)
$Button = GUICtrlCreateButton("Add", 136, 6, 75, 25)
$List = GUICtrlCreateListView("Values Added", 8, 40, 201, 214, _
        BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_AUTOARRANGE, $LVS_NOSORTHEADER, $WS_VSCROLL), _
        BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 175)
GUISetState(@SW_SHOW)

Global $aValues[1]

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            Add()
    EndSwitch
WEnd

Func Add()
    $value = GUICtrlRead($Input)
    If _ArraySearch($aValues, $value) = -1 And $value <> "" Then
        _ArrayAdd($aValues, $value)
        GUICtrlCreateListViewItem($value, $List)
        GUICtrlSetData($Input, "")
    Else
        MsgBox(16, "Error", "Value " & $value & " already exists!")
    EndIf
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    If $iwParam = 1 Then Add()
    Return "GUI_RUNDEFMSG"
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
Sign in to follow this  
Followers 0