[wxPython-users] Binding grid and data ?

Stef Mientki s.mientki at ru.nl
Sun Jul 1 03:03:14 PDT 2007


thanks Stephen,

the standard solution (everywhere seen on the web) works,
but after changing a value in the table,
you have to refresh the grid :-(
    self.grid.Refresh()

cheers,
Stef Mientki


Stephen Hansen wrote:
>
>     So is there a real binding between the grid and data ?
>     Should I write changing values directly to the grid ?
>     Or any other suggestions ?
>
>
> What I would do is write directly to the table-- but you will have to 
> provide an API for this. The table doesn't manage how you -store- your 
> data, it just provides a consistent API for the grid to -ask- the 
> table what data is where.
>
> You can add to your table subclass "SetValue(row, col, value)", and 
> then update your storage.
>
> The grid then has to be told that the table has had changes made to 
> it. You can create an 'UpdateValues' method of your table subclass, 
> such as:
>
> import wx.grid as gridlib
>
>     ...
>
>     def UpdateValues(self):
>         msg = gridlib.GridTableMessage(self, 
> gridlib.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
>         self.MyGrid.ProcessTableMessage(msg)
>
> That's assuming your table is storing a reference to the grid in 
> "self.MyGrid". I'd have the "SetValue" method of your table 
> automatically call self.UpdateValues() then.
>
>
> --S




More information about the wxpython-users mailing list