Re: Checking if entry is already in List




"Ken" <ken@xxxxxxxxxxx> wrote in message
news:uxEcjtGXFHA.3864@xxxxxxxxxxxxxxxxxxxxxxx
> Hi all!
>
> I'm looking for a fast method for adding items to a list, verifying if
> the item is already listed, in order to prevent doubles.
>
> Thanks a lot in advance for any ideas

You need to provide more information for any answer other than just a
general one. For example, is this "list" a ListBox or ListView or some
other control? Is it an array? A collection?

Generally, what you must do is loop through all the items and check yourself
to see if the item is already in the list. If the items happen to be in any
kind of collection (for example, the ListItems collection of a ListView
control), you can specify a key. Since keys must be unique, if an item with
the same key already exists, you'll get a trappable runtime error. This can
be a very effective way of preventing a duplicate from getting added to the
collection.

--
Mike
Microsoft MVP Visual Basic


.



Relevant Pages

  • RE: listview vertical scrollbar width
    ... ListView control encapsulates Windows build-in List-View to leverage its ... Windows has two kinds of scroll bars. ... You may use Spy++ to view ListView control structure and its windows style ... considered the non-client area of ListView, so this WS_VSCROLL scrollbar is ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Showing/Using Sort arrows on vb6 listviews?
    ... You specify them in an HDITEM structure and send the HDM_SETITEM message to the Header control. ... To get the hwnd of the Header control, you have to send the ListView an LVM_GETHEADER message. ... Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: ListView vs CheckListBox
    ... The application UI has a List View control and a Text Box and a Button. ... list view displays a list of files with checkboxes besides each file name. ... ListView.CheckedListViewItemCollection checkedItems = ... > is displayed with in my ListView, ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Autosizing Listview Columns
    ... > width of the columns after populating listview with items. ... The native listview control was design in such a way that, ... > PInvoke correctly resizes the columns, the other 3 regions all don't work ... > | private static extern int GetFocus(); ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Listviw SHOWSELALWAYS
    ... The ListView control has a HideSelection property which defaults ... > LVS_SHOWSELALWAYS is not an extended style, ... > Private Sub Form_Click ...
    (microsoft.public.vb.controls)