2012-01-03 29 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,或在刪除項目後手動清除代碼中的值。

相關問題