0

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.

Community
  • 1
  • 1
Mercifies
  • 152
  • 1
  • 13
  • 3
    Am I only one who can't see the image? – Soner Gönül Aug 03 '13 at 18:46
  • The link to the image gives a blank white image, so the uploaded image is the issue. – Tim Aug 03 '13 at 18:50
  • I'm not sure what your problem is? Is the code throwing an exception? Where is 'list' defined (the list that is your source for `localList` linq query) – Jay Aug 03 '13 at 19:10
  • the list (`list.where...`) you're trying to use is a global list of words you wish to predict and suggest. – DaMachk Aug 03 '13 at 19:22
  • I don't have list defined anywhere. Is there a way I can define list using an array? – Mercifies Aug 03 '13 at 19:45
  • `NameOfYourArray.ToList()` ? – Jay Aug 03 '13 at 19:46
  • When I change list to my array it throws an exception at z.StartsWidth – Mercifies Aug 03 '13 at 19:48
  • Figured out startswidth is a typo and should be StartsWith. Changed that and now it is bringing up another exception at toList() saying it doesn't contain a definition and no extension method – Mercifies Aug 03 '13 at 20:07
  • StartsWith is a method of string. You'll need to iterate over each element in your list and try StartsWith – Jay Aug 04 '13 at 01:54

1 Answers1

3

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.

Ehsan
  • 31,833
  • 6
  • 56
  • 65
  • Did you mean do not change the names of copied code? Good catch on the method name. – Jay Aug 03 '13 at 19:21