0

从标题中可以清楚地看出,我只添加到选定单元格的 datagridviewComboboxCell 完美地显示了它的下拉列表,我可以无缝地选择它们。当组合框失去焦点时会出现问题,它会忘记有关所选项目的所有内容并自动选择索引 0 处的项目,它的范围集合。很多时候,正在发生“DataGridViewDataErrorEvent”(我通过添加 DataError 事件处理程序来跟踪它)。我无法理解导致错误触发的问题所在。此外,即使我 daclare e.Cancel = false; 在事件处理程序中,ComboBox 自动选择索引 0 处的项目。请帮我解决这个问题。注意。我最初忘记添加(当它出现在屏幕上时!),DataGridViewComboBox 没有选择任何项目。编辑:- 代码片段

//Creating and Adding propertiesof     DataGridViewComboBoxCell.

RegViewdataGridView.Rows[uniqcustCount].Cells[day].ReadOnly = false;    //uniqcustCount & day Are Integers
var pcmbcell = new DataGridViewComboBoxCell();
var tcmbcell = new DataGridViewComboBoxCell();
RegViewdataGridView[day,uniqcustCount] = pcmbcell;
pcmbcell.ReadOnly = false;
pcmbcell.DropDownWidth = 80;
pcmbcell.DataSource = shipdPrdLst;
pcmbcell.DisplayStyle =      DataGridViewComboBoxDisplayStyle.ComboBox;
RegViewdataGridView.DataError += RegViewdataGridView_DataError;

 void RegViewdataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
    e.Cancel = false;
}
4

0 回答 0