I am trying to input an image file in a cell of wxGrid. I can't find an example in minimal wxGrid.
So looking around find some code, but can't make work. I am putting code.
Thank's
Jim
Code: Select all
class ImageGridCellRenderer : public wxGridCellStringRenderer
{
public:
virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected);
wxString image;
};
void ImageGridCellRenderer::Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected)
{
wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
wxImage cellImage;
if (cellImage.LoadFile(image))
{
wxBitmap cellBitmap(cellImage);
dc.DrawBitmap(cellBitmap, rect.x, rect.y);
}
else
{
wxLogError(_T("The image in cell:\n row '%d', column '%d',\n didn't load, does it exist?"), row, col);
grid.SetCellValue(row, col,_T("Here's should be an image"));
}
};
bool addimage(wxString s/*image file on disk*/)
{
m_grid1->SetCellValue(row,0,"image of file..");// col 0
// col 1 the image..
ImageGridCellRenderer* R =new ImageGridCellRenderer();
wxGridCellAttr *att=m_grid1->GetCellAttr(row,1);
R->Draw(s,m_grid1,att,wxPaintDC(this),wxRect(),row,1,1); // errors ..
m_grid1->SetCellRenderer(row, 1, R);
}