How to Check for Dups in ListView?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mr. B

    How to Check for Dups in ListView?

    The following code is how I check for duplicates in a List box. This is
    simple enough as there is only one column of stuff to check.

    ' Check for Duplicates
    ' Search listbox (from last to first)
    For cntr = lbDwgList.Items .Count - 1 To 1 Step -1
    ' If next item is a duplicate -> Remove It
    If lbDwgList.Items (cntr) = lbDwgList.Items (cntr - 1) Then _
    lbDwgList.Items .RemoveAt(cntr)
    Next

    But I've a ListView (2 columns) that I want to check for duplicates. Having 2
    columns is not the issue as I can check for a string of Col1+Col2.

    But like my Listbox example, I want to check Last Item to First Item (bottom
    to top). Both my ListBox and ListViews are sorted Ascending.

    In a ListView, how do I do a reverse check (never having done it before).

    The following of course does not work (because it doesn't search last to
    first). And it returns an Error anyways. (:

    ' Check for Duplicates
    i = lvModDwgs.Items .Count
    For Each LItem In lvModDwgs.Items
    ' If next item is a duplicate -> Remove It
    If LItem.SubItems( i).ToString = LItem.SubItems( i + 1).ToString Then _
    lvModDwgs.Items .RemoveAt(i)
    i = i + 1
    Next

    Anyone have any suggestions?

    Regards,

    Bruce
  • Mary Chipman

    #2
    Re: How to Check for Dups in ListView?

    If you are retrieving the names from a database, the best way is to
    use a SELECT DISTINCT when populating the listbox.

    --mary

    On Thu, 01 Jul 2004 17:56:45 GMT, Mr. B <User@NoWhere.c om> wrote:
    [color=blue]
    >The following code is how I check for duplicates in a List box. This is
    >simple enough as there is only one column of stuff to check.
    >
    > ' Check for Duplicates
    > ' Search listbox (from last to first)
    > For cntr = lbDwgList.Items .Count - 1 To 1 Step -1
    > ' If next item is a duplicate -> Remove It
    > If lbDwgList.Items (cntr) = lbDwgList.Items (cntr - 1) Then _
    > lbDwgList.Items .RemoveAt(cntr)
    > Next
    >
    >But I've a ListView (2 columns) that I want to check for duplicates. Having 2
    >columns is not the issue as I can check for a string of Col1+Col2.
    >
    >But like my Listbox example, I want to check Last Item to First Item (bottom
    >to top). Both my ListBox and ListViews are sorted Ascending.
    >
    >In a ListView, how do I do a reverse check (never having done it before).
    >
    >The following of course does not work (because it doesn't search last to
    >first). And it returns an Error anyways. (:
    >
    > ' Check for Duplicates
    > i = lvModDwgs.Items .Count
    > For Each LItem In lvModDwgs.Items
    > ' If next item is a duplicate -> Remove It
    > If LItem.SubItems( i).ToString = LItem.SubItems( i + 1).ToString Then _
    > lvModDwgs.Items .RemoveAt(i)
    > i = i + 1
    > Next
    >
    >Anyone have any suggestions?
    >
    >Regards,
    >
    >Bruce[/color]

    Comment

    • Mr. B

      #3
      Re: How to Check for Dups in ListView?

      With Deft Fingers, Mary Chipman <mchip@online.m icrosoft.com> wrote:
      [color=blue]
      >If you are retrieving the names from a database, the best way is to
      >use a SELECT DISTINCT when populating the listbox.[/color]

      Ah... sorry... I 'should' have mentioned that I'm not using a Data Base (:

      What happens is that I initially select files (DWG files)... then on the 2nd
      column I have names of Layout Tabs for each DWG file (there can be more than
      one Tab per DWG). The application allows a user to increase the number of
      Tabs per DWG file.

      In my ADD tab logic, I give it a name of "Layout#" where # is a sequential
      number (1, 2, 3, etc). So if a User has Layout1 and Layout2, and either adds
      more Layouts or renames a Layout to an existing Layout name, I want to delete
      the duplicates.

      Regards,

      Bruce

      Comment

      • The Grim Reaper

        #4
        Re: How to Check for Dups in ListView?

        I'd suggest putting all the data in your listviews into an ArrayList() or
        other Array based class. That way you can sort and filter through the array
        quickly and more reliably (you can remove items from an array at any time -
        unlike with a listview). Then simply dump the new array data back to the
        listview.
        _______________ _______________ ___
        The Grim Reaper

        "Mr. B" <User@NoWhere.c om> wrote in message
        news:t9n8e01h0p 0r3c2nq25u4vdi8 e57osa2tk@4ax.c om...[color=blue]
        > With Deft Fingers, Mary Chipman <mchip@online.m icrosoft.com> wrote:
        >[color=green]
        > >If you are retrieving the names from a database, the best way is to
        > >use a SELECT DISTINCT when populating the listbox.[/color]
        >
        > Ah... sorry... I 'should' have mentioned that I'm not using a Data Base (:
        >
        > What happens is that I initially select files (DWG files)... then on the[/color]
        2nd[color=blue]
        > column I have names of Layout Tabs for each DWG file (there can be more[/color]
        than[color=blue]
        > one Tab per DWG). The application allows a user to increase the number of
        > Tabs per DWG file.
        >
        > In my ADD tab logic, I give it a name of "Layout#" where # is a sequential
        > number (1, 2, 3, etc). So if a User has Layout1 and Layout2, and either[/color]
        adds[color=blue]
        > more Layouts or renames a Layout to an existing Layout name, I want to[/color]
        delete[color=blue]
        > the duplicates.
        >
        > Regards,
        >
        > Bruce[/color]


        Comment

        • Mr. B

          #5
          Re: How to Check for Dups in ListView?

          With Deft Fingers, "The Grim Reaper" <grim_reaper@bt openworld.com> wrote:
          [color=blue]
          >I'd suggest putting all the data in your listviews into an ArrayList() or
          >other Array based class. That way you can sort and filter through the array
          >quickly and more reliably (you can remove items from an array at any time -
          >unlike with a listview). Then simply dump the new array data back to the
          >listview.[/color]

          yeah... I kind of thought that was something like I'd have to do... just was
          hoping there was an easier way.

          Regards,

          Bruce

          Comment

          • Mr. B

            #6
            Re: How to Check for Dups in ListView?

            With Deft Fingers, "slaprade" <slaprade@discu ssions.microsof t.com> wrote:
            [color=blue]
            >I have had similar issues removing duplicates fro 120K items. I used hashtables. The hashtable uses a key/value pair. do something like this
            >Public MyHashtable as new hashtable
            >....
            >MyHashtable.it em(keyname) += 1[/color]

            Interesting! I've never used Hashtables (now Hash is another thing <grin>)...

            Thanks muchly... I'll play with this (probably better than dumping my stuff in
            a Listbox... then back to an array.

            Regards,

            Bruce

            Comment

            Working...