I have a ListView control that I'm filtering results from with a TextBox. The code works for highlighting the backcolors of the matching results, but I want to get the total found results/highlighted objects as an int
. The int
that is populating now is incorrect and not in line with the found/highlighted results.
How can I get the total number of found/highlighted results?
private void textBox1_TextChanged(object sender, EventArgs e)
{
foreach (ListViewItem lvi in this.browserlistview.Items)
{
if (textBox1.TextLength > 0)
{
if (lvi.Text.IndexOf(textBox1.Text, StringComparison.CurrentCultureIgnoreCase) >= 0)
{
Color b = Color.Cyan;
lvi.BackColor = b;
foundobjlbl.Text = "Objects found: " + lvi.Text.IndexOf(textBox1.Text, StringComparison.InvariantCultureIgnoreCase).ToString();
//this is turning up incorrect integers
}
else
{
Color w = Color.White;
lvi.BackColor = w;
}
}
else if (textBox1.TextLength == 0)
{
Color w = Color.White;
lvi.BackColor = w;
foundobjlbl.Text = "Objects found : 0";
}
}
}
Does anyone see where I'm going wrong?