In a textChanged event for a textBox I am trying to do a search function for ListBoxItems like below.
It seems that I have done the code correct but no items is selected and when writing a string that is longer in length than the item that is shortest in length, I get Compileerror that says, Index must be less than the collection.
What could be wrong in this code ?
String GetString = TextBox1.Text.ToLower();
String GetItemText = "";
int GetLength = GetString.Length;
for (int i = 0; i < eListBox2.Items.Count; i++)
{
if (eListBox2.Items[i].ToString().Length < GetLength)
{
GetItemText = eListBox2.Items[i].ToString();
if (GetItemText.Substring(0, GetLength).ToLower() == GetString)
{
eListBox2.SelectedIndex = i;
break;
}
}
}