Код: Выделить всё
private void ShiftColumnByOneRow(DataGridView dataGridView, int columnIndex)
{
if (dataGridView.Rows.Count > 1 && columnIndex >= 0 && columnIndex < dataGridView.Columns.Count)
{
// Store the value of the last cell in the column
var lastValue = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[columnIndex].Value;
// Shift each cell value down by one row
for (int i = dataGridView.Rows.Count - 1; i > 0; i--)
{
dataGridView.Rows[i].Cells[columnIndex].Value = dataGridView.Rows[i - 1].Cells[columnIndex].Value;
}
// Set the first cell value to the last cell value
dataGridView.Rows[0].Cells[columnIndex].Value = lastValue;
}
}
//Call this method when needed:
// Example usage
ShiftColumnByOneRow(yourDataGridView, columnIndex);
Я пробовал:
Код: Выделить всё
dataGridView.Rows[i-1].Cells[columnIndex].Value = dataGridView.Rows[i].Cells[columnIndex].Value;
Подробнее здесь: https://stackoverflow.com/questions/789 ... by-one-row