I have a simple grid and I want to move the cursor to the cell that a user right-clicks over so that a menu can pop up and then they can select to delete the contents in that cell. so I have the below function that almost works it seems to pick the cell that is one or two cells below where I click. the column is always correct, but the row is not exactly correct. Is there a known problem with this or am I doing something wrong? thanks!
Jeff
def OnGrid1GridCellRightClick(self, event):
(x,y) = event.GetPosition()
col = self.grid1.XToCol(x)
row = self.grid1.YToRow(y)
if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
self.grid1.SetGridCursor(row, col)
self.grid1.PopupMenu(self.GridPopMenu, (x,y))
I have a simple grid and I want to move the cursor to the cell that a user right-clicks over so that a menu can pop up and then they can select to delete the contents in that cell. so I have the below function that *almost* works it seems to pick the cell that is one or two cells below where I click. the column is always correct, but the row is not exactly correct. Is there a known problem with this or am I doing something wrong? thanks!
Jeff
def OnGrid1GridCellRightClick(self, event):
(x,y) = event.GetPosition()
col = self.grid1.XToCol(x)
row = self.grid1.YToRow(y)
if col != wx.NOT_FOUND and row != wx.NOT_FOUND:
self.grid1.SetGridCursor(row, col)
self.grid1.PopupMenu(self.GridPopMenu, (x,y))
The (x,y) are probably relative to the grid's grid subwindow since that is where the mouse events are coming from, but you are using that position as if it was relative to the main grid window. You can transform the position to be relative to the main grid window something like this: