wxPython Grid Control Row Selection
(for reference) I was attempting to create a grid control in wxPython that acted more like a list box (i.e. the selection was a row at a time rather than a cell at a time). The first thing that comes to mind is:
self.SetSelectionMode(wx.grid.Grid.SelectRows)
This works great for mouse events but for keyboard events (up, down, page up/down) it doesn’t work… it reverts back to cell-based selection. So, I then bound an event handler right after that previous line like this:
self.Bind(wx.grid.EVT_GRID_SELECT_CELL,self._onSelectCell)
All the above is in the __init__ method of my grid control subclass. Then, of course, I define the actual event handler:
def _onSelectCell(self,evt): self.SelectRow(evt.GetRow()) evt.Skip()
Basically, this just uses the row for the cell that is being selected and forces it to select the entire row and then the evt.Skip() allows it to finish it’s normal processing (which appears to be necessary). The only issue is that you can still sort of see the selected cell but at least it’s essentially working like I want it to.
Technorati Tags: python, wxpython, grid
No comments yet. Be the first.
Leave a reply