Refreshing part of the grid using virtual grid table

Hello list,

I am using wx.Grid with a virtual table. After some cell values are
changed in the virtual table, I'd like to have the Grid to display the
new values.

Now I used the following code adapted from the demo:

        msg = gridlib.GridTableMessage(self,
gridlib.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
        self.GetView().ProcessTableMessage(msg)

However, this message will tell wx.Grid object to refresh all its
display values, which tend to be somewhat slow. If I know exactly
which cell has its value changed, how can I request wx.Grid to refresh
only that cell?

···

--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn

Yuan HOng wrote:

Hello list,

I am using wx.Grid with a virtual table. After some cell values are
changed in the virtual table, I'd like to have the Grid to display the
new values.

Now I used the following code adapted from the demo:

       msg = gridlib.GridTableMessage(self,
gridlib.GRIDTABLE_REQUEST_VIEW_GET_VALUES)
       self.GetView().ProcessTableMessage(msg)

However, this message will tell wx.Grid object to refresh all its
display values, which tend to be somewhat slow. If I know exactly
which cell has its value changed, how can I request wx.Grid to refresh
only that cell?

Something like this should do it:

  grid = self.GetView()
  rect = grid.CellToRect(row, col)
  rect.SetPosition(grid.CalcScrolledPosition(rect.GetPosition()))
  grid.GetGridWindow().RefreshRect(rect)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

That works. And I found that the code below also works:

         grid = self.GetView()
         rect = grid.BlockToDeviceRect((row, col), (row, col))
         grid.GetGridWindow().RefreshRect(rect)

Is there any difference between the two?

···

On 9/24/06, Robin Dunn <robin@alldunn.com> wrote:

Something like this should do it:

        grid = self.GetView()
        rect = grid.CellToRect(row, col)
        rect.SetPosition(grid.CalcScrolledPosition(rect.GetPosition()))
        grid.GetGridWindow().RefreshRect(rect)

--
Hong Yuan

大管家网上建材超市
装修装潢建材一站式购物
http://www.homemaster.cn

Yuan HOng wrote:

···

On 9/24/06, Robin Dunn <robin@alldunn.com> wrote:

Something like this should do it:

        grid = self.GetView()
        rect = grid.CellToRect(row, col)
        rect.SetPosition(grid.CalcScrolledPosition(rect.GetPosition()))
        grid.GetGridWindow().RefreshRect(rect)

That works. And I found that the code below also works:

        grid = self.GetView()
        rect = grid.BlockToDeviceRect((row, col), (row, col))
        grid.GetGridWindow().RefreshRect(rect)

Is there any difference between the two?

No, they are essentially the same. Using BlockToDeviceRect will let you
include a range of cells if needed, and does some validation to ensure
that the range of cells is actually visible before returning the rectangle.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!