Advertisement
Guest User

Untitled

a guest
Jan 29th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. private: void ButtonUpClick(Object^ sender, EventArgs^ e) {
  2.     DataGridView^ grid = this->dataGridView;
  3.     try {
  4.         int totalRows = grid->Rows->Count;
  5.         int idx = grid->SelectedCells[0]->OwningRow->Index;
  6.         if (idx == 0) return;
  7.         int col = grid->SelectedCells[0]->OwningColumn->Index;
  8.         DataGridViewRowCollection^ rows = grid->Rows;
  9.         DataGridViewRow^ row = rows[idx];
  10.         rows->Remove(row);
  11.         rows->Insert(idx - 1, row);
  12.         grid->ClearSelection();
  13.         grid->Rows[idx - 1]->Cells[col]->Selected = true;
  14.     } catch (Exception^ e){
  15.     }
  16. }
  17.  
  18. private: void ButtonDownClick(Object^ sender, EventArgs^ e) {
  19.     DataGridView^ grid = this->dataGridView;
  20.     try {
  21.         int totalRows = grid->Rows->Count;
  22.         int idx = grid->SelectedCells[0]->OwningRow->Index;
  23.         if (idx == totalRows - 2) return;
  24.         int col = grid->SelectedCells[0]->OwningColumn->Index;
  25.         DataGridViewRowCollection^ rows = grid->Rows;
  26.         DataGridViewRow^ row = rows[idx];
  27.         rows->Remove(row);
  28.         rows->Insert(idx + 1, row);
  29.         grid->ClearSelection();
  30.         grid->Rows[idx + 1]->Cells[col]->Selected = true;
  31.     } catch (Exception^ e){
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement