wxGrid SetRenderer issues under MSW Topic is solved

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
kshitij_ds
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Jun 25, 2008 3:37 pm

wxGrid SetRenderer issues under MSW

Post by kshitij_ds » Fri Dec 12, 2008 5:47 pm

Hello All,

I have a wxGrid control in my application. I set renderer as follows:

SetCellRenderer(row,col, new myCellRenderer);
I do the above for every cell I add to the grid.

myCellRenderer class inherits from
wxGridCellStringRenderer
and it overrides the Draw method that draws text in the cell.

However, at anytime the Draw function is not executed.
This happens under Microsoft Windows...
While under Ubuntu, I noticed that the customized renderer works without any issues.


Any ideas on what might be going on?

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Fri Dec 12, 2008 7:02 pm

Hi,

It works just fine for me. What version OS / Widgets are you using?

Perhaps posting a bit more code would provide a clue.

Jim
OS: Vista SP1, wxWidgets 2.8.7.

kshitij_ds
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Wed Jun 25, 2008 3:37 pm

Post by kshitij_ds » Fri Dec 12, 2008 7:16 pm

I am using Ubuntu / wxWidgets 2.8.7...
Here is some code that might be of help:

myGrid = new ueGrid(this, ueID_MYID);
myGrid->CreateGrid(1,1);
myGrid->SetRowLabelSize(0);
myGrid->SetColLabelSize(0);
myGrid->SetDefaultColSize(180,true);
myGrid->SetDefaultRowSize(100,true);
myGrid->EnableGridLines(false);
myGrid->EnableEditing(false);
myGrid->SetCellRenderer(0,0, new myCellRenderer);

Above is define in main class that #include's myCellRenderer class.

Next.... I have derive myGrid class from wxGrid that has AppendMyCol method:

void myGrid::AppendMyCol(wxString head, wxString text)
{

//Here I just call this

SetCellValue(row,col,_("Kshitij"));
SetCellRenderer(row,col, new myCellRenderer);

}

Lastly..... myCellRenderer has this code:


void myCellRenderer::Draw(myGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected)
{
wxString cellText,cellHeader;

wxGridCellStringRenderer::Draw(grid, attr, dc,rect, row,col, isSelected);

dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(rect.x, rect.y, rect.GetWidth(), rect.GetHeight());
dc.SetPen(*wxBLACK_PEN);
}

myCellRenderer is derived from wxGridCellStringRenderer...

I hope this helps...

JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway » Sat Dec 13, 2008 12:05 am

Hi,

By changing wxGrid to myGrid in your declaration, you have not overridden the Draw method of wxGridCellStringRenderer.
You should change it back to wxGrid and then cast grid to myGrid. As follows:

Code: Select all

void myCellRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) 
{
myGrid *aGrid = (myGrid *) grid;
...
Hope that helps,

Jim

PS. you should have a look at the FAQ. Using the code tags makes your post easier to read.
OS: Vista SP1, wxWidgets 2.8.7.

Post Reply