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;
}

Well I Figured it out a couple days ago, forgot about this post. .. if anyones interested or just in case someone else has this problem ever -

 

The solution was to dump the list into an ArrayList Object, which has some awesome functions ..

 

Much Much faster also.

 

http://www.dotnetspider.com/kb/Article17.aspx

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.