wxGrid Cell dynamic change color

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tgui
Earned a small fee
Earned a small fee
Posts: 12
Joined: Fri Jan 04, 2008 7:07 pm

wxGrid Cell dynamic change color

Post by tgui »

Hi "y'all"

I've been working on a program that represents float data in a wxGrid.

The data in the table is between a certain range. Cell color is defined by a gradient of color that corresponds to the value within a cell. As a user modifies the data in a cell, what I'd like to do is have the cell color change to the appropriate color.

I can't get the cell colors to change with table data :(

I've extended the gridTableBase class, and in my SetValue method I've tried a number of things to trigger a color change. Please note that I have also implemented my own wxGridCellAttrProvider if that helps.

Within my GridTableBase::SetValue...
*not exact code*

Code: Select all

wxGridCellAttrProvider *provider = this->GetAttrProvider();
wxGridCellAttr *attr = provider->GetAttr(row, col, wxGridCellAttr::Any);
attr->SetBackgroundColour(*NEW COLOR);
Any hints? I'm at a loss here.

Thanks in advance!
-Eric-
clyde729
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Mon May 29, 2006 10:50 pm
Location: Jena, Germany

Post by clyde729 »

Have you tried (re-)setting the attr pointer?

Code: Select all

void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col)
could help. Also some Refresh / ForceRefresh methods can be called.
OS: Windows XP Home, Compiler: MingW, Version: wxWidgets 2.8.0, IDE: wx-Devcpp
tgui
Earned a small fee
Earned a small fee
Posts: 12
Joined: Fri Jan 04, 2008 7:07 pm

Post by tgui »

I passed around a reference to the wxGrid in my gridTableBase implementation. Not clean, but it works for now.

Code: Select all

this->parentFrame->dataGrid->SetCellBackgroundColour(row, col,  GetScaledColor(readValue, minValue, maxValue));
this->parentFrame->dataGrid->ForceRefresh();
Working screenshot. I'm working on my 2nd Subaru/EVO tuning program. 1st one in Java, now in C++ for more speed and better interface control.

Image
Post Reply