wxGrid %g renderer

Manuel Martín mmartin at ceyd.es
Mon Jun 25 12:05:46 PDT 2007


Hi

> > void SetScientificMode(SetScientificMode mode);
>
> How would I set this globally for a wxGrid? I guess my concern was what 
> string to pass in that would get mapped to this API.
>
> >From what I can see I can set per-column and per-cell renderers, and these 
> are passed by value, with a default copied to the whole grid.
>
> One thing that wasn't clear was how to use custom renderers with columns. I 
> see how to do it with cells. An example of registering a custom renderer 
> would be useful.
>   
To your question:
wxGrid::*SetColAttr*(*int */col/, *wxGridCellAttr 
<wx_wxgridcellattr.html#wxgridcellattr>* */attr/)
*wxGridCellAttr::SetRenderer 
<wx_wxgridcellattr.html#wxgridcellattr>***** 
<wx_wxgridcellattr.html#wxgridcellattr>**( 
<wx_wxgridcellattr.html#wxgridcellattr>*wxGridCellRenderer 
<wx_wxgridcellrenderer.html#wxgridcellrenderer>* */renderer/)**

Other approach,  I do in my grids, is use wxFormatValidator, which 
formats the user's input,
and store the formatted string in the grid's table.

wxGrid creates an editor just before showing it in a cell. I catch the 
message:
    EVT_GRID_CMD_EDITOR_CREATED(GRID_DAT, mmPanel::OnDefEditorCreated)

and just before deleting it:
    EVT_GRID_CMD_EDITOR_HIDDEN(GRID_DAT, mmPanel::OnDefEditorHidden)

The mmPanel members are:

void mmPanel::OnDefEditorCreated(wxGridEditorCreatedEvent& ev)
{
    if (ev.GetCol() > 0)
    {
        wxNumberValidator validor(wxT("-[@.###].','#E-##"), 
wxVAL_ON_KILL_FOCUS | wxVAL_ON_EDIT, NULL);
        wxTextCtrl *tc = (wxTextCtrl*) ev.GetControl();
        tc->SetValidator(validor);
    }
    ev.Skip();
}

//On_Kill_Focus and OnEnter will not reach the validator, so validate now
void mmPanel::OnDefEditorHidden(wxGridEvent& ev)
{
    if (ev.GetCol() > 0)
    {
        bool res = false;
        wxNumberValidator* vali =
           (wxNumberValidator*) mygrid->GetCellEditor(ev.GetRow(), 
ev.GetCol())->GetControl()->GetValidator();
        if (vali)
        {
            res = vali->Validate(this);
            if (res)
                vali->SetFormatted();
            else
            {
                ev.Veto();
                return; //with NO ev.Skip
            }
        }
    }
    ev.Skip();
}







More information about the wx-users mailing list