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
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?
– user6026
I believe I can answer even with the question being a little vague. Could reopen the topic?
– Reiksiel
the post was reformulated.
– Fernando Neves
@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 InterfaceIEquatable<T>
, try this and let me know =). If you open the topic I put a more complete answer.– Reiksiel
@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.
– Fernando Neves
Did you find a solution? Poste as an answer to help other people.
– Maniero
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.
– EduardoFernandes
I don’t know C#, but I wouldn’t have a Hashmap< > that would make it look like Java?
– Wellington Avelino