【问题标题】:Creating autocomplete for multiline textbox problems为多行文本框问题创建自动完成
【发布时间】:2013-08-04 20:34:22
【问题描述】:

好吧,所以图像不工作所以这里是代码本身

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

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

目前的问题是:

listBox1.KeyDown += listBox1_SelectedIndexChanged;

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

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

【问题讨论】:

  • 只有我一个看不到图片吗?
  • 图片的链接给出了一个空白的白色图片,所以上传的图片是问题。
  • 我不确定您的问题是什么?代码是否抛出异常? 'list' 定义在哪里(localList linq 查询的来源列表)
  • 您尝试使用的列表 (list.where...) 是您希望预测和建议的单词的全局列表。
  • 我没有在任何地方定义列表。有没有办法可以使用数组定义列表?

标签: c# listbox c#-3.0


【解决方案1】:

你没有任何方法listbox1_SelectedIndexChanged。所以改变

listBox1_SelectedIndexChanged

listBox_SelectedIndexChanged

并且您已将 List 加粗。它必须是您没有向我们展示的某些对象的列表。更改名称。

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

【讨论】:

  • 您的意思是不要更改复制代码的名称吗?方法名称很好。
猜你喜欢
  • 1970-01-01
  • 2016-01-20
  • 2012-10-09
  • 1970-01-01
  • 2020-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-05
相关资源
最近更新 更多