防止 ComboBox 在数据源更改时更新显示的文本

Prevent ComboBox from updating displayed text when datasource changes

我有一个绑定到 BindingList 的 ComboBox。 背景是我想从下拉列表中选择一个选项(作为建议),但如果 ItemsSource 发生变化,我不想更改显示的文本(例如,当我将项目添加到绑定列表)。

有没有办法在项目源更改时阻止组合框更新显示的文本?

一些代码:

this.comboBox1.DataSource = database.ListItems; // database.ListItems is of type BindingList<string>

public void update_ListItems(BindingList<string> ListItems)
{
    ListItems.Add("Item"); // Causes an update of the displayed text in the ComboBox 
}

如果您需要打破 ComboBox 和数据源之间的绑定,您可以像这样将 BindingList 转换为 List:

this.comboBox1.DataSource = database.ListItems.ToList();

这将阻止在您更改 BindingList 时更新 ComboBox 项目