Cheers Brian, I will find this very useful.
Regards,
Andrew
···
-----Original Message-----
From: Brian Kelley [mailto:bkelley@wi.mit.edu]
Sent: 14 May 2003 15:15
To: wxPython-users@lists.wxwindows.org
Cc: ajp@eutechnyx.com
Subject: Re: [wxPython-users] wxgrid
Andrew Perella wrote:
Thanks Robin, great help as always.
I have another quick quesstion I have been strugglng with. I am using a
gridtablebase and want to change the number of rows etc.
I have tried appending rows on the wxgrid and overiding the AppendRows
method on the gridtable (returning TRUE from that method) but the grid is
never refreshed and the rows added. I seem to be missing a Grid.Recalc
method or suchlike.
Any ideas?
Andrew.
This is actually a little complicated. You need to send insert/delete
events to the grid to add or delete rows. Here is a sample, notice that
you need to save the number of cols and number of rows to see whether
the grid size has changed (self._cols, self._rows). The functions you
need are in self.UpdateValues and self.ResetView. Simply call
self.ResetView(grid) when the table size changes. grid is the wxGrid
parent.
Since this comes up a lot, I propose adding a sample to the demo where
you can add/delete columns and rows using the gridtablebase. If Robin
wants one I will make a full example and pass it along.
class KitTable(wxPyGridTableBase):
"""
A custom wxGrid Table using a metakit view
"""
def __init__(self, table, importTable=0):
wxPyGridTableBase.__init__(self)
self.table = table
self._cols = self.GetNumberCols()
self._rows = self.GetNumberRows()
def GetNumberCols(self):
return self.table.cols
def GetNumberRows(self):
return self.table.rows
def GetColLabelValue(self, col):
return self.table.headers[col]
def GetRowLabelValue(self, row):
return str(row)
def GetValue(self, row, col):
return str( self.table[row, col] )
def ResetView(self, grid):
grid.BeginBatch()
for current, new, delmsg, addmsg in [
(self._rows, self.GetNumberRows(),
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
wxGRIDTABLE_NOTIFY_ROWS_APPENDED),
(self._cols, self.GetNumberCols(),
wxGRIDTABLE_NOTIFY_COLS_DELETED,
wxGRIDTABLE_NOTIFY_COLS_APPENDED),
]:
if new < current:
msg = wxGridTableMessage(self,delmsg,new,current-new)
grid.ProcessTableMessage(msg)
elif new > current:
msg = wxGridTableMessage(self,addmsg,new-current)
grid.ProcessTableMessage(msg)
self.UpdateValues(grid)
grid.EndBatch()
self._rows = self.GetNumberRows()
self._cols = self.GetNumberCols()
grid.Refresh()
def UpdateValues(self, grid):
"""Update all displayed values"""
msg = wxGridTableMessage(self, wxGRIDTABLE_REQUEST_VIEW_GET_VALUES)
grid.ProcessTableMessage(msg)
--
Brian Kelley bkelley@wi.mit.edu
Whitehead Institute for Biomedical Research 617 258-6191
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
_____________________________________________________________________
This e-mail is confidential and may be privileged. It may be read, copied
and used only by the intended recipient. No communication sent by e-mail to
or from Eutechnyx is intended to give rise to contractual or other legal
liability, apart from liability which cannot be excluded under English law.
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Control Centre.
www.eutechnyx.com Eutechnyx Limited. Registered in England No: 2172322
_____________________________________________________________________
This e-mail is confidential and may be privileged. It may be read, copied and used only by the intended recipient. No communication sent by e-mail to or from Eutechnyx is intended to give rise to contractual or other legal liability, apart from liability which cannot be excluded under English law.
This message has been checked for all known viruses by Star Internet delivered through the MessageLabs Virus Control Centre.
www.eutechnyx.com Eutechnyx Limited. Registered in England No: 2172322