Remove Duplicate Items Listview C#

Asked

Viewed 755 times

0

I would like to remove items that have the same title, as shown in the image, but would like to do after the items are listed in the listview.

I couldn’t do anything because the "title" may be the same but the "links" are not, and this meant that I couldn’t use the ". Distinct()"

thanks

inserir a descrição da imagem aqui

the code of how they are added in listview.

    List<string> links = new List<string>();
    List<string> titles = new List<string>();

    List<string> links1 = new List<string>();
    List<string> titles1 = new List<string>();

 private void btSearch_Click(object sender, EventArgs e)
 {
        if (txSearch.Text.Length != 0)
        {
            ScanServe();
            for (int i = 0, j = 0 , r = 0 ; i < titles.Count && j < links.Count && r < sizes.Count ; i++, j++ , r++)
            {
                string juntos = titles[i].ToString() + ";" + links[j].ToString() + ";" + sizes[r].ToString();
                string texto = ".mp3";
                string texto2 = titles[i].ToString();

                if (juntos.Contains(texto))
                {
                    string[] split = juntos.Split(';');

                    titles1.Add(split[0].ToString());
                    links1.Add(split[1].ToString());
                    sizes1.Add(split[2].ToString());
                }
            }
            for (int q = 0, w = 0 ,z = 0; q < titles1.Count && w < links1.Count && z < sizes1.Count; q++, w++, z++)
            {
                listView1.Items.Add(new ListViewItem(new string[] { titles1[q], links1[w],sizes1[z] }));
            }
        }
    }
  • Explain better?

  • 1

    I believe I can answer even with the question being a little vague. Could reopen the topic?

  • the post was reformulated.

  • @user7862, following what you need to do is use the method Enumerable.Distinct<TSource> Method (IEnumerable<TSource>), but for this you need to define a way to differentiate the items of the list, for this, implement the Interface IEquatable<T>, try this and let me know =). If you open the topic I put a more complete answer.

  • @Reiksiel thank you I will give a forehead and look more on this in google, I am inciante,I entered in this world of programming just 1 month ago.

  • Did you find a solution? Poste as an answer to help other people.

  • Why not instead of removing duplicate items you do not check if it has not already been inserted? To do this keep a Dictionary part having as key the title that can not repeat.

  • I don’t know C#, but I wouldn’t have a Hashmap< > that would make it look like Java?

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.