Setting the cell value with wxGridChoiceCellEditor

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
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Setting the cell value with wxGridChoiceCellEditor

Post by ONEEYEMAN »

Hi, ALL,
I have a wxGrid object.
One of the cells has an attached wxChoiceCellEditor (which is wxComboBox).
What I'd like to do is show the editor and when the user make a selection and the editor closes - if the user chooses the specific string reset the cell value back to empty string.

So I have the following code:

Code: Select all

void MyDialog::OnCellLeftClicked(wxGridEvent &event)
{
    auto row = event.GetRow();
    auto column = event.GetCol();
    if( row == 1 )
    {
        m_grid->ShowCellEditControl();
        wxGridCellChoiceEditor *editor = (wxGridCellChoiceEditor *) m_grid->GetCellEditor( row, column );
        wxComboBox *combo = (wxComboBox *) editor->GetControl();
        //
        combo->Bind( wxEVT_COMBOBOX_CLOSEUP, &QuickSelect::OnSortClosing, this );
        //
        wxString value = m_grid->GetCellValue( row, column );
        combo->Popup();
        editor->DecRef();
        m_column = column;
    }
}

void QuickSelect::OnSortClosing(wxCommandEvent &event)
{
    wxComboBox *object = wxDynamicCast( event.GetEventObject(), wxComboBox );
    if( object->GetStringSelection() == _( "(not sorted)" ) )
    {
       m_grid->SetCellValue( 1, m_column, "" );
    }
}
Problem is it doesn't work. I still see the value "(not sorted)" (without quotes).

I tried to use CallAfter, like this:

Code: Select all

        CallAfter( &m_grid->SetCellValue/*( 1, m_column, "" )*/, 1, m_column, "" );
but it gives me a compiler error:
error C2276: '&': illegal operation on bound member function expression
Is there a workaround?

Thank you.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Setting the cell value with wxGridChoiceCellEditor

Post by Kvaz1r »

ONEEYEMAN wrote: Mon May 06, 2019 4:38 am I tried to use CallAfter, like this:
What if passed to CallAfter lambda expression and make corresponding call there?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Setting the cell value with wxGridChoiceCellEditor

Post by ONEEYEMAN »

Hi,
Tried with

Code: Select all

        CallAfter( []{ m_grid->SetCellValue( 1, m_column, "" )};
Got
error C4573: the usage of 'MyDialog::m_grid' requires the compiler to capture 'this' but the current default capture mode does not allow it
Thank you.

P.S.: I'm not well-versed in C++11.
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Setting the cell value with wxGridChoiceCellEditor

Post by Kvaz1r »

Hi. You should capture this :

Code: Select all

 CallAfter( [this](){ m_grid->SetCellValue( 1, m_column, "" )});
If it won't help I think better provide minimal example for testing.
Post Reply