Hi,
I am trying to use cut and paste in a grid...
Regrettably I am having problems finding the "selection".
My app uses a table driven grid.
In the definition of the table object I have the following:
# we need to do this before the call to autoresizecols
self.grid.SetTable(self,False)
self.grid.SetSelectionMode(wx.grid.Grid.SelectRows)
The definition of the grid look like ( method list abreviated...)
class MyGrid(wx.grid.Grid):
def __init__(self,parent):
wx.grid.Grid.__init__(self,parent)
self.lastPopup = None
self.popupmenu = wx.Menu()
for text in ["View As Text Field", "View As Binary Image","Export Field..."] :
item = self.popupmenu.Append(-1,text)
self.Bind(wx.EVT_MENU,self.OnPopupItemSelected,item)
#self.GetGridWindow().Bind(wx.EVT_CONTEXT_MENU,self.OnShowPopup)
self.Bind(wx.grid.EVT_GRID_CELL_RIGHT_CLICK,self.OnShowPopup)
self.Bind(wx.EVT_CHAR, self.OnChar)
def OnChar(self,evt):
foo=evt.GetKeyCode()
bar = evt.CmdDown()
baz = self.IsSelection()
if sys.platform=='darwin' : code = 99 # 'c'
else: code = 3 # windows and unix
if (evt.GetKeyCode() == code) and evt.CmdDown() and self.IsSelection():
rows = self.GetSelectedRows()
wx.MessageBox("rows: "+str(rows))
return
evt.Skip(True)
When I populate the grid and click on a row ( not the row label) and
do a cmd-c the dialog in OnChar shows row to be an empty list.ie even though
the row is highlighted and IsSelection() is true, rows = empty list.
If I click on a row label and then do a cmd-c I get the row number-1 in the
list, the correct answer.
If I click on a row header and shift click on another row header, everything between
the two rows appears to be selected. When I cmd-c, again rows is set to the empty
list.
If I click on a row header and cmd-click on another row header then the additional row
appears to be added to the selection. This time I will get the two correct row numbers
in the list when I do a cmd-c.
Questions:
when I click on an actual row ( not the row header ) it appears to be selected
IsSelection returns true but GetSelectedRows() fails. Why?
When I click on a row header and then shift click on a different row header, it
appears that all of the rows between the two clicked on rows are selected and
IsSelection returns true but GetSelectedRows() returns an empty list. Why?
Is there anyway I can force only one row to be selected at a time?
Thanks,
Jerry