[C#] 데이터 그리드 뷰 에서 버튼으로 row 위치 변경
private void btnGoUp_Click(object sender, EventArgs e)
{
if (dgvList.CurrentRow.Index <= 0) return;
//
int _iCurrentRow = dgvList.CurrentRow.Index;
DataGridViewRow _dgvRow = dgvList.Rows[_iCurrentRow];
dgvList.Rows.RemoveAt(_iCurrentRow);
dgvList.Rows.Insert(_iCurrentRow - 1, _dgvRow);
dgvList.Rows[_iCurrentRow - 1].Selected = true;
dgvList.CurrentCell = dgvList[dgvList.CurrentCell.ColumnIndex, _iCurrentRow - 1];
}
private void btnGoDown_Click(object sender, EventArgs e)
{
if (dgvList.CurrentRow.Index < 0 || dgvList.CurrentRow.Index + 1 == dgvList.Rows.Count) return;
//
int _iCurrentRow = dgvList.CurrentRow.Index;
DataGridViewRow _dgvRow = dgvList.Rows[_iCurrentRow];
dgvList.Rows.RemoveAt(_iCurrentRow);
dgvList.Rows.Insert(_iCurrentRow + 1, _dgvRow);
dgvList.Rows[_iCurrentRow + 1].Selected = true;
dgvList.CurrentCell = dgvList[dgvList.CurrentCell.ColumnIndex, _iCurrentRow + 1];
}
{
if (dgvList.CurrentRow.Index <= 0) return;
//
int _iCurrentRow = dgvList.CurrentRow.Index;
DataGridViewRow _dgvRow = dgvList.Rows[_iCurrentRow];
dgvList.Rows.RemoveAt(_iCurrentRow);
dgvList.Rows.Insert(_iCurrentRow - 1, _dgvRow);
dgvList.Rows[_iCurrentRow - 1].Selected = true;
dgvList.CurrentCell = dgvList[dgvList.CurrentCell.ColumnIndex, _iCurrentRow - 1];
}
private void btnGoDown_Click(object sender, EventArgs e)
{
if (dgvList.CurrentRow.Index < 0 || dgvList.CurrentRow.Index + 1 == dgvList.Rows.Count) return;
//
int _iCurrentRow = dgvList.CurrentRow.Index;
DataGridViewRow _dgvRow = dgvList.Rows[_iCurrentRow];
dgvList.Rows.RemoveAt(_iCurrentRow);
dgvList.Rows.Insert(_iCurrentRow + 1, _dgvRow);
dgvList.Rows[_iCurrentRow + 1].Selected = true;
dgvList.CurrentCell = dgvList[dgvList.CurrentCell.ColumnIndex, _iCurrentRow + 1];
}
댓글
댓글 쓰기