繁体   English   中英

为多行文本框问题创建自动完成

[英]Creating autocomplete for multiline textbox problems

好了,因此图像无法正常工作,所以这是代码本身

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();
        }
    }

我遇到了一些错误,想知道是否有人可以帮助我。 我正在使用这个问题的答案。 任何帮助表示赞赏。

当前的问题是:

listBox1.KeyDown + = listBox1_SelectedIndexChanged ;

List localList = list .Where(z => z.StartsWidth(textBox1.Text))。toList();

我的错误以粗体突出显示。

您没有任何方法listbox1_SelectedIndexChanged 所以改变

listBox1_SelectedIndexChanged

listBox_SelectedIndexChanged

并且您已经加粗了List 它必须是您未显示给我们的某些对象的列表。 更改名称。

注意:复制时,请更改代码中定义的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM