Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
Why do I find the result repeats after the search?
Mohamed Moumni
7y
190
1
Reply
i use this methode to search for every keyword in textbox1 ind have the result in the listbox2 . But the problem that the results are repeated .
this code used in search button
private
void
button1_Click(
object
sender, EventArgs e)
{
// the keyword in text box
string
[] pattern = textBox1.Text.Split(
new
[] {
' '
},StringSplitOptions.RemoveEmptyEntries);
// list_temporare for items in listbox 1
List<DirectoryInfo> list_temporare =
new
List<DirectoryInfo>();
// listbox2 for show result
listBox2.Items.Clear();
// add all items in listbox1 in list_temporare (Because linq and lambda does not support the items in the box list or that what I believe)
foreach
(DirectoryInfo dr
in
listBox1.Items)
{
list_temporare.Add(dr);
}
// search for every key word in pattern
var liste_resultat = (from drc
in
list_temporare
where pattern.All(s => drc.ToString().ToLower().Contains(s.ToLower()))
select drc);
// show result in listbox2
foreach
(DirectoryInfo dr
in
liste_resultat)
{
listBox2.Items.Add(dr);
}
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
HOW TO SAVE IMAGE IN FOLDER AFTER CREATE SETUP IN C# WIN APP
AutoMapper Issue