【发布时间】:2016-09-13 05:31:34
【问题描述】:
我正在做一个使用列表框的项目,我可以添加项目、删除项目、更新项目但我无法搜索, 这是我的搜索代码
string search = Person.listperson[listBox1.SelectedIndex].lastname;
foreach (String s in search)
{
if (s.Equals(textBox6.Text))
{
//show searched items
MessageBox.Show("Success!");
}
}
你能帮我解决这个问题吗? 谢谢:)
我这里有一个搜索代码, 但它不适用于按钮,我怎样才能将它应用到按钮上?
private void textBox6_TextChanged(object sender, EventArgs e)
{
int index = listBox1.FindString(this.textBox6.Text);
if (0 <= index)
{
listBox1.SelectedIndex = index;
}
}
【问题讨论】:
-
我想,我不能使用'foreach' :(
-
什么是 Person.listperson 是另一个列表框吗?我对你在做什么有点困惑。看起来您正在 listBox1 中选择一个项目,然后使用它的索引从Something中选择一个姓氏?它只给你一个不实现 IEnumerable 的字符串,所以你不能使用 foreach。
-
这是我的搜索代码:D