我有一个DatagridviewCombobox
列,并在每一行上创建 DatagridviewCombobox 单元格并向其中添加项目。当我更改任何(组合框)单元格的值时,它会抛出一个异常,Datagridviewcombobox cell value is not valid.
并且单元格值变为“1”。
我正在处理该datagridview_currentcelldirtystatechange
事件,但无法使其正常工作。
下面的代码是创建行并用序列号填充组合框单元格。
int _rowLimit =1;
for (int i = _rowLimit - 1; i < _rowLimit; i++)
{
datagridview.Rows.Add();
item = i + 1;
datagridview[myColumn, i].Value = _rowLimit;
DataGridViewComboBoxCell oCell = datagridview.CurrentRow.Cells[myColumn] as DataGridViewComboBoxCell;
oCell.Items.Add(item);
((DataGridViewComboBoxColumn)datagridview.Columns[myColumn]).Items.IndexOf(_rowLimit);
((DataGridViewComboBoxColumn)datagridview.Columns[myColumn]).Items.Insert(index, item);
}
以下是我正在做的datagridview_currentcelldirtystatechange
事情:
for (int innerIndex = 0; innerIndex < datagridview.Rows.Count; innerIndex++)
{
long sequence = 3;
long oldSequence = 2;
long tempValue= Convert.ToInt64(datagridview.Rows[innerIndex].Cells[myColumn].Value);
if (tempValue <= sequence && tempValue> oldSequence)
{
datagridview.Rows[innerIndex].Cells[myColumn].Value = tempValue+ 1; // increment the sequence
// value here i am getting is correct , but it doesn't show in the DatagridviewCombobox cell where it gets changed of gridview and the mentioned exception is thrown.
}
任何帮助,将不胜感激。谢谢。