Fixed bug in when deleting row in CustomGrid
authorLaurent Bessard
Thu, 30 May 2013 11:36:47 +0200
changeset 1196 d2f4061cdff5
parent 1195 8f8d9859e9fc
child 1197 eb118ed5cbe0
Fixed bug in when deleting row in CustomGrid
controls/CustomGrid.py
--- a/controls/CustomGrid.py	Thu May 30 09:46:22 2013 +0200
+++ b/controls/CustomGrid.py	Thu May 30 11:36:47 2013 +0200
@@ -93,7 +93,7 @@
             self.Table.InsertRow(new_row, self.DefaultValue.copy())
             self.Table.ResetView(self)
         if new_row is not None:
-            self.SetSelectedRow(new_row)
+            self.SetSelectedCell(new_row, col)
 
     def DeleteRow(self):
         self.CloseEditControl()
@@ -105,7 +105,8 @@
             else:
                 self.Table.RemoveRow(row)
                 self.Table.ResetView(self)
-            self.SetSelectedRow(min(row, self.Table.GetNumberRows() - 1))
+            if self.Table.GetNumberRows() > 0:
+                self.SetSelectedCell(min(row, self.Table.GetNumberRows() - 1), col)
 
     def MoveRow(self, row, move):
         self.CloseEditControl()
@@ -117,10 +118,9 @@
             if new_row != row:
                 self.Table.ResetView(self)
         if new_row != row:
-            self.SetSelectedRow(new_row)
+            self.SetSelectedRow(new_row, col)
     
-    def SetSelectedRow(self, row):
-        col = self.GetGridCursorCol()
+    def SetSelectedCell(self, row, col):
         self.SetGridCursor(row, col)
         self.MakeCellVisible(row, col)
         self.RefreshButtons()