C# 从数据索引组合框中删除项

C# 从数据索引组合框中删除项,c#,combobox,datasource,C#,Combobox,Datasource,在我的代码中,我只是尝试实现自动完成combobox,它具有搜索子字符串的能力,我在按键事件上执行以下编码,但由于combobox中的数据被数据库绑定,因此我得到错误:当DataSource属性设置为时,无法修改Items集合 请更正下面的代码: cboAuthor.DroppedDown = true; object[] originalList = (object[])cboAuthor.Tag; if (originalList == null) { // backup origina

在我的代码中,我只是尝试实现自动完成combobox,它具有搜索子字符串的能力,我在按键事件上执行以下编码,但由于combobox中的数据被数据库绑定,因此我得到错误:
当DataSource属性设置为
时,无法修改Items集合

请更正下面的代码:

cboAuthor.DroppedDown = true;

object[] originalList = (object[])cboAuthor.Tag;
if (originalList == null)
{
 // backup original list
 originalList = new object[cboAuthor.Items.Count];
 cboAuthor.Items.CopyTo(originalList, 0);
 cboAuthor.Tag = originalList;
}

// prepare list of matching items
string s = cboAuthor.Text.ToLower();
IEnumerable<object newList = originalList;
if (s.Length  0)
{
 newList = originalList.Where(item = item.ToString().ToLower().Contains(s));
}

// clear list (loop through it, otherwise the cursor would move to the beginning of the textbox...)
while (cboAuthor.Items.Count  0)
{
 cboAuthor.Items.RemoveAt(0);

}

// re-set list
cboAuthor.Items.AddRange(newList.ToArray());
cboAuthor.DroppedDown=true;
object[]originalList=(object[])cboautor.Tag;
if(originalList==null)
{
//备份原始列表
originalList=新对象[cboAuthor.Items.Count];
cboAuthor.Items.CopyTo(原始列表,0);
cboAuthor.Tag=原始列表;
}
//准备匹配项的列表
字符串s=cboAuthor.Text.ToLower();

IEnumerablefind如何将ListCollectionView与筛选器一起使用。我在windows中工作form@ArunaVerma:通过邮件将您的代码发送给我:gaurav@brillbrains.com@ArunaVerma soulotion仍然在同一个方向上collectionview为您提供了一个过滤功能,以便创建视图(类似于数据库中的视图)(它实际上不删除项,但只显示其中的一个子集。这可以在winforms中使用Bindings来实现。错误提示:从数据源中删除它!