Fix row selection in CustomGrid
authorLaurent Bessard
Tue, 05 Mar 2013 17:54:19 +0100
changeset 961 069466072e9d
parent 955 7ef2f485c28f
child 962 c0dcbbdb0bb1
Fix row selection in CustomGrid
controls/CustomGrid.py
--- a/controls/CustomGrid.py	Mon Mar 04 17:49:38 2013 +0900
+++ b/controls/CustomGrid.py	Tue Mar 05 17:54:19 2013 +0100
@@ -92,9 +92,8 @@
         else:
             self.Table.InsertRow(new_row, self.DefaultValue.copy())
             self.Table.ResetView(self)
-        self.SetGridCursor(new_row, col)
-        self.MakeCellVisible(new_row, col)
-        self.RefreshButtons()
+        if new_row is not None:
+            self.SetSelectedRow(new_row)
 
     def DeleteRow(self):
         self.CloseEditControl()
@@ -106,10 +105,7 @@
             else:
                 self.Table.RemoveRow(row)
                 self.Table.ResetView(self)
-            new_row = min(row, self.Table.GetNumberRows() - 1)
-            self.SetGridCursor(new_row, col)
-            self.MakeCellVisible(new_row, col)
-            self.RefreshButtons()
+            self.SetSelectedRow(min(row, self.Table.GetNumberRows() - 1))
 
     def MoveRow(self, row, move):
         self.CloseEditControl()
@@ -121,10 +117,14 @@
             if new_row != row:
                 self.Table.ResetView(self)
         if new_row != row:
-            self.SetGridCursor(new_row, col)
-            self.MakeCellVisible(new_row, col)
-            self.RefreshButtons()
-
+            self.SetSelectedRow(new_row)
+    
+    def SetSelectedRow(self, row):
+        col = self.GetGridCursorCol()
+        self.SetGridCursor(row, col)
+        self.MakeCellVisible(row, col)
+        self.RefreshButtons()
+        
     def OnAddButton(self, event):
         self.AddRow()
         self.SetFocus()