Сдвинуть DataGridView на одну строку вверхC#

Место общения программистов C#
Ответить
Anonymous
 Сдвинуть DataGridView на одну строку вверх

Сообщение Anonymous »

Я нашел этот код для смещения столбца на одну строку вниз:

Код: Выделить всё

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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»