【发布时间】: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' 定义在哪里(
localListlinq 查询的来源列表) -
您尝试使用的列表 (
list.where...) 是您希望预测和建议的单词的全局列表。 -
我没有在任何地方定义列表。有没有办法可以使用数组定义列表?