code: def OnGridSelection(self, event):
          
  
          current_table = copy(self.main_window.grid.current_table)
  
          post_command_event(self, self.GridActionTableSwitchMsg,
                             newtable=self.last_table)
          if is_gtk():
              try:
                  wx.Yield()
              except:
                  pass
  
          sel_start, sel_stop = self.last_selection
  
          shape = self.main_window.grid.code_array.shape
          selection_string = event.selection.get_access_string(shape,
                                                               current_table)
  
          self.Replace(sel_start, sel_stop, selection_string)
          self.last_selection = sel_start, sel_start + len(selection_string)
  
          post_command_event(self, self.GridActionTableSwitchMsg,
                             newtable=current_table)
docs: Event handler for grid selection in selection mode adds text