2012-01-03 38 views
0

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

我试着做一个datagridview.refresh(),但它仍然没有帮助。

1)你应该不需要刷新后打电话到EndEdit中:它正从工具条菜单项

// _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();   
+1

你是否正在移动或更改正确事件中的绑定。你可以粘贴你正在使用的代码..?还datagridview.Bind()或绑定听起来像是要看的东西..只是猜测这里没有看到你的代码 – MethodMan 2012-01-03 22:33:58

+0

你可以显示如何绑定BindingLists组合框列? dataGridView1是否处于虚拟模式? – Kimberly 2012-01-03 23:42:36

回答

1

东西要注意/看着夫妇叫。如果需要调用它,则应该在刷新之前调用它。

2)如果您的组合框包含DropDown的DropDownStyle,那么这是预期的行为。

MSDN documentation

如果将DropDownStyle属性到下拉菜单中,您可以在组合框的编辑区域中键入任意值。

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