直到昨天,下面的代码工作正常,但今天我收到一条错误消息 Argument out of exception & index out of range。
我在这里尝试做什么,从index 3(4th col)
最后一行的开始,取那个单元格值并放入col 3 (index 2) cell
. 当我在最后一个单元格(从下到上)中键入它时,我收到了上述错误消息。
请帮我。
private void datagridview_CellValidated(object sender, CellValidatedEventArgs e)
{
if (e.ColumnIndex != 3)
return;
int nextRowIndex = e.RowIndex -1;
int lastRowIndex = datagridview.Rows.Count;
try
{
if (nextRowIndex <= lastRowIndex)
{
var valuesForcell = datagridview.Rows[e.RowIndex].Cells[3].Value.ToString();
datagridview.Rows[nextRowIndex].Cells[2].Value = valuesForcell;
datagridview.Rows[nextRowIndex].Cells[2].ReadOnly = true;
datagridview.Rows[nextRowIndex].Cells[2].Style.ForeColor = Color.MediumVioletRed;
datagridview.ClearSelection();
datagridview.SelectionMode = GridViewSelectionMode.CellSelect;
datagridview.Rows[nextRowIndex].Cells[3].BeginEdit();
}
}
catch (Exception exception) { }
}