Win7 + MinGW32 + wxWidgets3.0.0 + Codebocks13.12
I want to show some data(from database) in wxgrid.
Therefore, I create a class customTable: public wxGridTableBase, and bind it with wxGrid by using SetTable().
And then I need merge every 3 cells of first column:
for example: merge cell(0,0) + (1,0) + (2,0); cell(3,0) + (4,0) + (5,0); ................
Here I can not use wxGrid->SetCellSize(...), because I didn't call CreateGrid(), I use SetTable() instead.
And I checked the sample grid source codes. I found that may be I should create a customer wxGridCellAttrProvider, and do merge cell in GetAttr();
Here it is:
Code: Select all
virtual wxGridCellAttr *GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
{
wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
wxLogMessage(wxString::Format("GetCellAttr(%d,%d);", row, col));
//first merge cells for Corner
if((col < 1) && (n > 1))
{
//ensure attr existed
if(!attr)
{
attr = new wxGridCellAttr();
attr->SetBackgroundColour(m_colBg);
attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER);
attr->SetRenderer(new wxGridCellAutoWrapStringRenderer());
}
//set different size for each cell in order to merge cells
if(row % n)
{
attr->SetSize(-(row % n), 0);
}
else
{
attr->SetSize(n, 1);
}
return attr;
}
// for other common cell
if(!attr)
{
attr = m_attrData;
attr->IncRef();
}
return attr;
};
the defaut data for grid is only 1 cell, If I press the 'ToggleData' button, the data for grid will be changed to 9 rows and 4 cols.
Here I click the cell(0,0) once.
Then If I press the 'ToggleData' button again in order to change the data for grid back to 1 cell, I will get the incorrect CellSize for cell(0,0).
pls check my screenshot or run my app.
pls help, thank you.
Tao