0

我有一个 DataGridView,其中有一个单元格是 DataGridViewComboCell。每个 DataGridViewComboCell 都绑定到 BindingList 的唯一副本。当我从绑定列表中删除一个项目时,组合框会删除我从绑定列表中删除的条目。
但是,如果选择了该值,则它会保留为单元格中的选定项。

我尝试做一个 datagridview.refresh(),但它仍然没有帮助。它是从工具条菜单项中调用的

  // _contractLists is List<BindingList<String>> which is the datasource for a datagridviewcombobox

List<String> removedList = new List<string>();
_contractSelForm.ShowDialog();
_contractSelForm.GetandClearRemovedContracts(ref removedList);

foreach (BindingList<String> contractList in _contractLists)
{
     // remove deleted favorites
    foreach (string contract_name in removedList)
    {
         contractList.Remove(contract_name);
    }
}  

dataGridView1.Refresh();
dataGridView1.EndEdit();          
4

1 回答 1

1

需要注意/看的几件事:

1)您不需要在刷新后调用 EndEdit。如果需要调用,应该在 Refresh 之前调用。

2)如果您的组合框有一个 DropDownStyle 的 DropDown,那么我这是预期的行为。

MSDN 文档

如果将 DropDownStyle 属性设置为 DropDown,则可以在 ComboBox 的可编辑区域中键入任何值。

要更改此设置,请将 DropDownStyle 更改为 DropDownList 或在删除项目后手动清除代码中的值。

于 2012-01-04T03:57:32.403 回答