wxGrid woes (wxGrid::SetCellSize(), disabling cells,
wxGridCellChoiceEditor, native controls)
Volker Bartheld
dr_versaeg at freenet.de
Wed Mar 14 04:30:27 PDT 2007
Hi!
I want to disable a certain range of colums in one row of a wxGrid and
later re-enable them. In disabled state "Disabled" should be written in
grey across all disabled colums, later the original
editors/renderers/values should be restored - see the example attached
below.
It seems that
1) the cell attributes and values of the spanned/combined cells (with
SetCellSize) are not restored after unspanning/uncombining them. In the
example, cells 2-3 in row 0 are still empty, readonly and don't have
their wxGridCellChoiceEditor back.
2) If the cell in row 0/colum 1 shows its native editor (the combobox)
while it gets spanned/disabled, the editor stays in place.
Is there anything I can do about this? I'm using wxMSW2.8.0.
Thanks a lot for your help,
Volker
<gridtest.cpp>
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/timer.h>
#include <stdlib.h>
static const wxString sOptions[] = { wxT("One"), wxT("Two"), wxT("Three") };
enum tTIMER_IDS { eTIMER_COMBINE=0x01, eTIMER_SEPARATE };
class MyDialog : public wxDialog
{
public:
enum tDLG_IDS { ID_BUTTON=wxID_HIGHEST+1, ID_GRID };
MyDialog::MyDialog() : wxDialog(NULL, wxID_ANY, wxT("wxGrid"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE)
{
wxBoxSizer *pSizerV=new wxBoxSizer( wxVERTICAL );
wxGrid* pGrid=new wxGrid(this, ID_GRID, wxDefaultPosition, wxSize(500, 256));
pGrid->CreateGrid(8, 4, wxGrid::wxGridSelectRows);
pGrid->SetColLabelValue(0, wxT("Options"));
for(int j=1; j<pGrid->GetNumberCols(); ++j)
{
pGrid->SetColLabelValue(j, wxString::Format(wxT("Value %i"), j-1));
for(int i=0; i<pGrid->GetNumberRows(); ++i)
{
if(1==j)
{
pGrid->SetCellValue(i, 0, wxString::Format(wxT("%i"), i));
pGrid->SetCellAlignment(i, 0, wxALIGN_LEFT, wxALIGN_CENTRE);
pGrid->SetReadOnly(i, 0);
}
pGrid->SetCellRenderer(i, j, new wxGridCellStringRenderer());
pGrid->SetCellEditor(i, j, new wxGridCellChoiceEditor(WXSIZEOF(sOptions), sOptions));
pGrid->SetCellValue(i, j, sOptions[rand()*WXSIZEOF(sOptions)/RAND_MAX]);
}
}
pSizerV->Add(pGrid);
SetSizer(pSizerV);
pSizerV->SetSizeHints(this);
m_timer1=new wxTimer(this, eTIMER_COMBINE); m_timer1->Start(5000, true);
m_timer2=new wxTimer(this, eTIMER_SEPARATE); m_timer2->Start(10000, true);
}
void MyDialog::OnClose(wxCloseEvent&) { delete m_timer1; delete m_timer2; Destroy(); }
void MyDialog::OnTimer(wxTimerEvent& evt)
{
wxGrid* pGrid;
switch(evt.GetId())
{
case eTIMER_COMBINE:
pGrid=(wxGrid*)FindWindow(ID_GRID);
pGrid->SetCellSize(0, 1, 1, 3);
pGrid->SetReadOnly(0, 1);
pGrid->SetCellValue(wxT("Disabled"), 0, 1);
pGrid->SetCellTextColour(0, 1, wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
pGrid->SetCellAlignment(0, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
pGrid->ForceRefresh();
break;
case eTIMER_SEPARATE:
pGrid=(wxGrid*)FindWindow(ID_GRID);
pGrid->SetCellSize(0, 1, 1, 1);
pGrid->SetReadOnly(0, 1, false);
pGrid->SetCellValue(sOptions[0], 0, 1);
pGrid->SetCellTextColour(0, 1, wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
pGrid->SetCellAlignment(0, 1, wxALIGN_LEFT, wxALIGN_CENTRE);
pGrid->ForceRefresh();
break;
default: evt.Skip(); break;
}
}
wxTimer *m_timer1, *m_timer2;
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(MyDialog,wxDialog)
EVT_CLOSE(MyDialog::OnClose)
EVT_TIMER(wxID_ANY, MyDialog::OnTimer)
END_EVENT_TABLE()
class MyApp: public wxApp
{
public:
bool MyApp::OnInit()
{
MyDialog* TheDialog=new MyDialog();
TheDialog->Show();
return true;
}
};
IMPLEMENT_APP(MyApp)
</gridtest.cpp>
__
Mail replies to/an V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list