TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
osyris zosar
NA
289
27.1k
Lambda problem I can not seem to figure out.
Jan 11 2021 1:57 AM
I really have no idea how to figure this out, please help.
I have this filter button that is suppose to filter a listbox based on what is filled in a textbox and a list that is used to add the names the listbox
this is my code:
public
void
FilterButton_Click(
object
sender, RoutedEventArgs e)
{
//2 filter examples I used
bool
Agemin =
int
.TryParse(AgeBoxMin.Text,
out
int
AgeMi);
//first filter
if
(Agemin && AgeBoxMin.Text.Length != 0 && (AgeBoxMax.Text.Length == 0 || Agemax !=
true
))
{
filtercount++;
int
T = 0;
while
(T < AgeListNumb.Count)
{
if
(AgeListNumb[T] > AgeMi)
{
IndexAge.Add(T);
TotalFilter.Add(T);
}T++;}}
//second filter
if
(JobTextBox.Text.Length != 0)
{ filtercount++;
int
P = 0;
while
(P < JobList1.Count)
{
if
(JobList1[P].ToLower().Contains(JobTextBox.Text.ToLower()))
{
IndexJob.Add(P);
TotalFilter.Add(P);
}P++;}}
// the filter system:
(probable the problem)
var matches = TotalFilter.GroupBy(x => x).Where(x => x.Count() == filtercount).Select(x => x.Key).ToList();
// applying filter to Listbox
if
(filtercount != 0 && matches.Any())
{
AccountNamesList.Items.Clear();
foreach
(var I
in
matches)
AccountNamesList.Items.Add(Listboxlist[I]);
}
//(Listboxlist contains random names, those names are created with a function)
}
The first time i run it it runs perfect just as i want it,
But the second time i use the above code it doubles
matches
I have looked up what happend with the matches list:
messageBox.Show(Matches.Aggregate(
"Matches indexes : "
, (s1, s2) => s1 +
" , "
+ s2);
If i use the first filter and i allow all items in
Listboxlist
to pass( filling in 0 in AgeBoxMin(textbox))
it gives the output:
(If listboxlist would contain 6 items )
1,2,3,4,5,6
If i do it again
I get the output: 1,2,3,4,5,6,7,8,9,10,11,12
for some reason it doubles it and makes the entire program crash
because list box only contains 6 items not 12.
Maybe somehow it stores all the items in "var matches" and adds it all up.
Reply
Answers (
5
)
Data Saving After Closing
Upload pdf file on another server.