/* -------------- Move up in the row ------------------*/
1 private void move ToolStripMenuItem_Click (object sender, EventArgs e) 2 {3 DataGridView curgrd = null; 4 curgrd = dgvSub; 5 6 if (curgrd. currentRow = null) 7 return; 8 9 curgrd. endEdit (); 10 11 int selectedRowIndex = curgrd. currentRow. index; 12 if (selectedRowIndex> = 1) 13 {14 // copy the selected row 15 DataGridViewRow newRow = curgrd. rows [selectedRowIndex]; 16 17 // Delete the selected row 18 curgrd. rows. remove (curgrd. rows [selectedRowIndex]); 19 20 // Insert the copied row to the position 21 curgrd of the selected row. rows. insert (selectedRowIndex-1, newRow); 22 23 // select the initially selected row 24 curgrd. currentCell = curgrd. rows [selectedRowIndex-1]. cells [0]; // set the current row to 25} 26}
/* -------------- Move the row down ------------------*/
1 private void move down ToolStripMenuItem_Click (object sender, EventArgs e) 2 {3 DataGridView curgrd = null; 4 curgrd = dgvSub; 5 6 if (curgrd. currentRow = null) 7 return; 8 9 curgrd. endEdit (); 10 11 int selectedRowIndex = curgrd. currentRow. index; 12 if (selectedRowIndex <curgrd. rows. count-1) 13 {14 // copy the selected row 15 DataGridViewRow newRow = curgrd. rows [selectedRowIndex]; 16 17 // Delete the selected row 18 curgrd. rows. remove (curgrd. rows [selectedRowIndex]); 19 20 // Insert the copied row to the position 21 curgrd of the selected next row. rows. insert (selectedRowIndex + 1, newRow); 22 23 // select the initially selected row 24 curgrd. currentCell = curgrd. rows [selectedRowIndex + 1]. cells [0]; // set the current row to 25} 26}