【发布时间】:2013-02-07 00:27:56
【问题描述】:
我做了一个列表框,它工作得很好,我也做了一个搜索功能,但我想隐藏列表框中的项目,只在通过索引搜索时显示它们。 这是我添加项目的代码
private void Savebtn_Click(object sender, EventArgs e)
{
addTolist(gatherItem());
refreshView();
}
private void addTolist(Person p)
{
Person.listperson.Add(p);
}
private void refreshView()
{
listBox1.Items.Add(getItem());
}
private String getItem()
{
String result = null;
foreach (Person p in Person.listperson)
{
result = p.lastname;
}
return result;
}
这是我的搜索代码
private void button1_Click(object sender, EventArgs e)
{
int index = listBox1.FindString(textBox6.Text);
if (0 <= index)
{
listBox1.SelectedIndex = index;
}
}
有办法吗?谢谢:)
【问题讨论】: