Binding grid and data ?

hello,

I've the a wx.grid, attached to a data_table,
like this:

class CustTableGrid ( gridlib.Grid ):
  def __init__(self, parent, data, Device):
    gridlib.Grid.__init__(self, parent, -1)
    self.table = CustomDataTable ( data )
    self.SetTable ( self.table, True )

Now I thought that there was a binding between the data and the grid.
As my grid shows options of shape on my screen,
I've to update the grid when for example an object on the screen is moved.
Changing the value in the dataset, doesn't seem to have any effect
(I also couldn't find something like a Refresh / Update).
The rest of the program works because I can update the grid by changing it's cellvalue.

works:
    self.grid.SetCellValue(3,1,'684');
   doesn't work:
  self.grid.table.SetValue(3,1,684)
doesn't work:
  self.grid.table.data[3][1] = 684

Now I could to a new "SetTable" , but I read somewhere that it's not a good idea to do that more than once.

So is there a real binding between the grid and data ?
Should I write changing values directly to the grid ?
Or any other suggestions ?

thanks,
Stef Mientki

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

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 :frowning:
    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