2011-01-21 37 views
2
dataGridView.Rows.Add(
    metaData.Offset.ToString("X2"), 
    metaData.Length, 
    metaData.Format,  // This parameter goes to a ComboBox cell which throws an 
    metaData.Description, //  exception above      
    null, 
    null); 

以編程方式將數據分配給DataGridViewComboBoxCell的有效方法是什麼?System.ArgumentException:DataGridViewComboBoxCell值無效

+0

整個片斷是一個語句,因此一行。 – leppie 2011-01-21 05:08:21

+1

如果您需要給DataGridViewComboBoxColumn檢查值http://stackoverflow.com/questions/4744384/how-to-set-value-in-datagridviewcomboboxcolumn-from-a-datatable/4744550#4744550 – Binil 2011-01-21 06:49:26

回答

12

要解決此問題,只需爲DataGridView添加「DataError」即可。這就是所有步驟:雙擊datagridview並從事件列表中選擇「dataerror」事件。

DataError事件使您能夠處理在數據處理操作期間由控件調用的代碼中拋出的異常。

完蛋了:)

0

爲了解決這個問題,DataGridView中添加的 「DataError」 事件,然後

只是這樣寫:e.Cancel = TRUE;

e.g:

private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e) 
{ 
    e.Cancel = true; 
}