Index: frmEditGrid.cpp =================================================================== RCS file: /projects/pgadmin3/src/ui/frmEditGrid.cpp,v retrieving revision 1.56 retrieving revision 1.57 diff -Lsrc/ui/frmEditGrid.cpp -Lsrc/ui/frmEditGrid.cpp -u -w -r1.56 -r1.57 --- src/ui/frmEditGrid.cpp +++ src/ui/frmEditGrid.cpp @@ -488,6 +488,18 @@ if (optionsChanged) Go(); } +template < class T > +int ArrayCmp(T *a, T *b) +{ + if (*a == *b) + return 0; + + if (*a > *b) + return 1; + else + return -1; +} + void frmEditGrid::OnDelete(wxCommandEvent& event) { wxMessageDialog msg(this, _("Are you sure you wish to delete the selected row(s)?"), _("Delete rows?"), wxYES_NO | wxICON_QUESTION); @@ -498,22 +510,17 @@ wxArrayInt delrows=sqlGrid->GetSelectedRows(); int i=delrows.GetCount(); + // Sort the grid so we always delete last->first, otherwise we + // could end up deleting anything because the array returned by + // GetSelectedRows is in the order that rows were selected by + // the user. + delrows.Sort(ArrayCmp); + // don't care a lot about optimizing here; doing it line by line // just as sqlTable::DeleteRows does - if (delrows.Item(i-1) > delrows.Item(0)) - { while (i--) sqlGrid->DeleteRows(delrows.Item(i), 1); - } - else - { - int j = 0; - while (j < i) - { - sqlGrid->DeleteRows(delrows.Item(j), 1); - ++j; - } - } + sqlGrid->EndBatch();