combobox as dataview renderer

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
fusebox
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Aug 17, 2009 9:37 pm

combobox as dataview renderer

Post by fusebox » Fri Feb 26, 2010 5:11 pm

Hi folks.

Im trying to use a combobox as a dataview editor in my program. The code runs well but the editor is shown for less than half a second then it vanishes.

Has anyone hacked this one succesfully?

xin.songtao
Experienced Solver
Experienced Solver
Posts: 86
Joined: Wed Apr 18, 2007 6:10 am
Location: Shanghai China

Post by xin.songtao » Thu Mar 04, 2010 3:34 am

Im trying to use a combobox as a dataview editor in my program. The code runs well but the editor is shown for less than half a second then it vanishes.
the combobox with owner-drawn list items,you should implement OnDrawItem() OnMeasureItem() and OnMeasureItemWidth() method.

the editor is shown for less than half a second then it vanishes, it maybe draw the items only once.

you can take a look at sample " widgets ", it maybe help you.
from: Shanghai China
language: C++/C
platform:MSW\MacOS\Linux
Email: [email protected]

fusebox
In need of some credit
In need of some credit
Posts: 7
Joined: Mon Aug 17, 2009 9:37 pm

Post by fusebox » Thu Mar 04, 2010 8:31 pm

I have gone through the samples and i have seen implementation of a wxDataViewChoiceRenderer that uses a choicebox for in place editing

here is the create editor implementation

Code: Select all

wxControl* wxDataViewChoiceRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
{
    wxString s = value;
    wxSize size = labelRect.GetSize();
#ifdef __WXMAC__
    size = wxSize( wxMax(70,labelRect.width ), -1 );
#endif
    wxChoice *c = new wxChoice( parent, wxID_ANY, labelRect.GetTopLeft(), size, m_choices );
    c->SetStringSelection( value.GetString() );

    return c;
}
I derived my custom

Code: Select all

wxDataViewComboboxRenderer
from

Code: Select all

wxDataViewCustomRenderer
and tried to overide the above method like so

Code: Select all

wxControl* wxDataViewComboRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
{
    wxString s = value;
    wxSize size = labelRect.GetSize();
#ifdef __WXMAC__
    size = wxSize( wxMax(70,labelRect.width ), -1 );
#endif

    wxComboBox *c = new wxComboBox(parent, wxID_ANY, s, labelRect.GetTopLeft(), size);


    c->SetValue( value.GetString() );

    return c;
}
But the above code results in the unwanted operation i described.

Post Reply