I want to change only selected cell color. But it change all cell color.
The problem I’m having is that when I call SetBackgroundColour the cell always change all cell on grid.
Please advise me.
Here is the event handler I have attached to wx.grid.EVT_GRID_SELECT_CELL:
it seems to me that all your Cells share the same GridCellAttr(). If you want to change the background for one cell only, you need to clone the GridCellAttr, change the background colour of the new GridCellAttr and SetAttr(newAttr, selected_row, selected_col).
I attach a sample app, which hopefully will show it to you.
it seems to me that all your Cells share the same GridCellAttr(). If you want to change the background for one cell only, you need to clone the GridCellAttr, change the background colour of the new GridCellAttr and SetAttr(newAttr, selected_row, selected_col).
I attach a sample app, which hopefully will show it to you.
In your example CustomDataTable.GetAttr() always returns the same GridCellAttr (CustomDataTable.color_attr). That’s why all your cells have the same backgroundcolour. You can’t have one GridCellAttr with different backgroundcolours. If you wan’t one cell with another backgroundcolour, you need to have another GridCellAttr.
Isn’t the core of the problem that the OP is mixing two concepts?
E.g. see the demo: GridSimple.py vs. GridCustTable.py or
Grid_MegaExample.py.
table.SetAttr can be used with GridSimple.py.
The attribute will be stored in the table. The table will hold all
the data and attributes.
This will work for relatively small tables.
But for a grid with a CustomDataTable(gridlib.PyGridTableBase) the
attributes are not stored in the grid.
They need to be returned by CustomDataTable.GetAttr instead whenever
a cell is to be rendered.
In the example code here, OnLeftClick calls GetOrCreateCellAttr.
This will call CustomDataTable.GetAttr, which will return the single
shared instance and then this is either
modified in place and so the whole grid is affected or
cloned and modified and so this does not have any effect, as the
next call to GetAttr will return the shared instance again.
So the CustomDataTable.GetAttr needs to check whether the cell is in
the selection or not and return the appropriate
attributes.
Regards,
Dietmar
···
Am 05.11.2015 um 22:45 schrieb Torsten:
In your example CustomDataTable.GetAttr() always returns the same
GridCellAttr (CustomDataTable.color_attr ). That’s
why a ll your cells have the same backgroundcolour. You
can’t have one GridCellAttr with different backgroundcolours. If
you wan’t one cell with another backgroundcolour, you need to
have another GridCellAttr.