我试图用文本框中的文本过滤一个列表框,realTime.
这是代码:
private void SrchBox_TextChanged_1(object sender, EventArgs e)
{
var registrationsList = registrationListBox.Items.Cast<String>().ToList();
registrationListBox.BeginUpdate();
registrationListBox.Items.Clear();
foreach (string str in registrationsList)
{
if (str.Contains(SrchBox.Text))
{
registrationListBox.Items.Add(str);
}
}
registrationListBox.EndUpdate();
}
Run Code Online (Sandbox Code Playgroud)
以下是问题:
当我运行该程序时,我收到此错误: Object reference not set to an instance of an object
如果我点击退格键,我的初始列表将不再显示.这是因为我的实际物品清单现在减少了,但我怎样才能做到这一点?
你能为我指出正确的方向吗?