Jump to content

[SOLVED] C#, Removing Duplicate items in a listview.


jscix

Recommended Posts

Okay, This code actually works.. but it is Ridiculously slow. (and I know, I know.... Don't use goto.. :/ )

 

well, For some reason the ListView control isn't enumerable(I've read somewhere you can add in functionality, but I'm still a noob.)

 

Anyway.. I'm wondering if anyone has a better alternative for this, or can help me correct my code, to make it faster.

 

DreamWords is the ListView object.

 

   int curind = 0;
            int cntdw = (DreamWords.Items.Count - 1);
            int innerind = 0;
            int Dup = 0;
            DreamWords.Focus();
            while (curind <= cntdw)
            {
                cntdw = (DreamWords.Items.Count - 1);
                DreamWords.Items[curind].Selected = true;
                string curword1 = DreamWords.SelectedItems[0].Text;
                curind++;
                while (innerind <= cntdw)
                {
                restart:
                    ;
                    cntdw = (DreamWords.Items.Count - 1);
                    if (innerind > cntdw) { innerind--; goto restart; }
                    DreamWords.Items[innerind].Selected = true;
                    string curword2 = DreamWords.SelectedItems[0].Text;
                    if (curword2.Equals(curword1)) { Dup++; }
                    if (Dup == 2) { DreamWords.SelectedItems[0].Remove(); curind = 0; }
                    innerind++;
                }
                Dup = 0;
                innerind = 0;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.