Reputation: 662
I want to allow the user to select more rows in a Grid by holding the Shift-Button while clicking on the first and on the last row the user want to select. I have tested this:
def OnRangeSelect(self, event):
if event.Selecting():
top = event.GetTopRow()
bottom = event.GetBottomRow()
while top <= bottom:
print bottom
self.myGrid.SelectRow(top, True)
top += 1
event.Skip()
and this:
def OnRangeSelect(self, event):
event.Skip()
but always the same happen...
but there are tricky things happen:
1) The function is calling -> all right
2) It doesn't select the rows although it goes into the loop(testet with the PyDev debugger)
3) If I select e.G. row 3 as top row and row 6 as bottom row, wxPython select all rows from 0 upto 6...
I don't know what to do...
Python-Version: 2.7
wxPython-Version 2.9
Upvotes: 0
Views: 395
Reputation: 584
Refer this code it might help:
import wx
import wx.grid as gridlib
class MyGrid(gridlib.Grid):
def __init__(self, parent):
"""Constructor"""
gridlib.Grid.__init__(self, parent)
self.CreateGrid(12, 8)
self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.OnshiftSelect)
def OnshiftSelect(self, evt):
if evt.Selecting():
msg = 'Selected'
else:
msg = 'Deselected'
print "OnshiftSelect: %s top-left %s, bottom-right %s\n" % (msg, evt.GetTopLeftCoords(),
evt.GetBottomRightCoords())
evt.Skip()
class MyForm(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, parent=None, title="Grid events")
panel = wx.Panel(self)
myGrid = MyGrid(panel)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(myGrid, 1, wx.EXPAND)
panel.SetSizer(sizer)
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
Upvotes: 1