Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private: void ButtonUpClick(Object^ sender, EventArgs^ e) {
- DataGridView^ grid = this->dataGridView;
- try {
- int totalRows = grid->Rows->Count;
- int idx = grid->SelectedCells[0]->OwningRow->Index;
- if (idx == 0) return;
- int col = grid->SelectedCells[0]->OwningColumn->Index;
- DataGridViewRowCollection^ rows = grid->Rows;
- DataGridViewRow^ row = rows[idx];
- rows->Remove(row);
- rows->Insert(idx - 1, row);
- grid->ClearSelection();
- grid->Rows[idx - 1]->Cells[col]->Selected = true;
- } catch (Exception^ e){
- }
- }
- private: void ButtonDownClick(Object^ sender, EventArgs^ e) {
- DataGridView^ grid = this->dataGridView;
- try {
- int totalRows = grid->Rows->Count;
- int idx = grid->SelectedCells[0]->OwningRow->Index;
- if (idx == totalRows - 2) return;
- int col = grid->SelectedCells[0]->OwningColumn->Index;
- DataGridViewRowCollection^ rows = grid->Rows;
- DataGridViewRow^ row = rows[idx];
- rows->Remove(row);
- rows->Insert(idx + 1, row);
- grid->ClearSelection();
- grid->Rows[idx + 1]->Cells[col]->Selected = true;
- } catch (Exception^ e){
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement