im working on a program in which a user has to be able to filter a datagridview thats populated with words from a dictonaryfile in txt format.
the program has a input field where the user can input a filter, the inputfield(textbox)
in this case the filter is in the folowing format:
%filter keyword%
so i wrote a function for it, however im having the folowing problem: it does filter some values but it doesnt remove all false entries so i have to press the filter button multiple times in order to get rid of all rows not containing the filter word.
the code:
private bool kwfilter(DataGridView dgview, string filter)
{
if (filter.Contains("%") == true) //look if the filterstring does contain the % parameter used for this type of filtering.
{
try
{
string[] tmp = filter.Split(char.Parse("%"));
string containfilter = containfilter = tmp[1]; // so for example if filter is %monkey% then containfilter would be monkey
foreach (DataGridViewRow row in dgview.Rows)
{
if (row.Cells[0].Value.ToString().Contains(containfilter) == false)// if the row's first cell doesnt contain the value of string containfilter , then remove the row
{
dgview.Rows.Remove(row);
}
}
} catch(Exception e){
MessageBox.Show(e.Message);
return false;
}
}
return false; // if the filter doesnt contain the filter parameter % then just return false
}
the code i use to call the function:
if (kwfilter(dtgrid_keywords, txtkwfilter_keyword.Text.ToString()) == true)
{
MessageBox.Show("containfilter succesfully applied");
}
else
{
MessageBox.Show("a error ocurred while applying the keyword filter, please check the syntax and try again");
}
hope someone can explain why my function wont get rid of all bad entries in one run...
Thanks in advance,
Alexander Jeurissen

New Topic/Question
Reply




MultiQuote





|