Reputation: 152
Alright so the images weren't working so here is the code itself
private void textBox_KeyUp(object sender, KeyEventArgs e)
{
listBox1 = new ListBox();
Controls.Add(listBox1);
var x = textBox1.Left;
var y = textBox1.Top + textBox1.Height;
var width = textBox1.Width + 20;
const int height = 40;
listBox1.SetBounds(x, y, width, height);
listBox1.KeyDown += listBox1_SelectedIndexChanged;
List<string> localList = list.Where(z => z.StartsWidth(textBox1.Text)).toList();
if (localList.Any() && !string.IsNullOrEmpty(textBox1.Text))
{
listBox1.DataSource = localList;
listBox1.Show();
listBox1.Focus();
}
}
void listBox_SelectedIndexChanged(object sender, KeyEventArgs e)
{
if (e.KeyValue == (decimal)Keys.Enter)
{
textBox1.Text = ((ListBox)sender).SelectedItem.ToString();
listBox1.Hide();
}
}
I have run into some errors and was wondering if anyone could help me with them. I am using the answer to this question. Any help is appreciated.
Current problems are:
listBox1.KeyDown += listBox1_SelectedIndexChanged;
List localList = list.Where(z => z.StartsWidth(textBox1.Text)).toList();
My errors are highlighted in bold.
Upvotes: 0
Views: 683
Reputation: 32671
You don't have any method listbox1_SelectedIndexChanged
. So change
listBox1_SelectedIndexChanged
to
listBox_SelectedIndexChanged
and you have bolded out List. It has to be your list of some object, which you haven't shown us. Change the name.
Note: When you copy do change the names as they are defined in your code.
Upvotes: 3