Reorder column, Resize column events

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
Anil8753
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sat Jan 16, 2016 5:57 am

Reorder column, Resize column events

Post by Anil8753 » Sun Jan 24, 2016 12:03 pm

I have a wxDataViewCtrl. I am performing the following actions:

Reorder column using mouse drag&drop
Resize column using mouse drag&drop

Here I want to get notify above actions via wx events. My requirement is to record all above actions by the user so that while next launch of application can restore the user customization.

I did not find any wxDataViewEvent for this purpose, that I can handle.

I found only wxEVT_DATAVIEW_COLUMN_REORDERED and this is also not getting fired on windows.

Please help me out.

User avatar
doublemax
Moderator
Moderator
Posts: 14597
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Reorder column, Resize column events

Post by doublemax » Sun Jan 24, 2016 12:43 pm

Try wxEVT_HEADER_END_RESIZE and wxEVT_HEADER_END_REORDER.
http://docs.wxwidgets.org/trunk/classwx ... _ctrl.html
Use the source, Luke!

Anil8753
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sat Jan 16, 2016 5:57 am

Re: Reorder column, Resize column events

Post by Anil8753 » Mon Jan 25, 2016 11:15 am

Thanks :)

GetMainWindow() API is there to get associated main window. There is no API available to get the associated wxHeaderCtrl from the wxDataViewCtrl.

I used the following trick :(

Code: Select all

    wxWindowList childWinList = m_pDataViewCtrl->GetChildren();

    for (const auto& win : childWinList)
    {
        wxHeaderCtrl* pHeaderWin = dynamic_cast<wxHeaderCtrl*>(win);

        if (pHeaderWin)
        {
            pHeaderWin->Bind(wxEVT_HEADER_END_RESIZE, &JobListCtrlEventHandler::OnColumnResized, this);
            pHeaderWin->Bind(wxEVT_HEADER_END_REORDER, &JobListCtrlEventHandler::OnColumnReordered, this);
        }
    }

I know this is not good, but I didn't find other good way to get wxHeaderCtrl window.

One more issue is:

wxEVT_HEADER_END_REORDER event is fired before the actual update in UI.

When I use wxDataViewCtrl::GetColumn(unsigned int) API to get the column, it gives me the non-updated column. Is there any way to get notify after UI update after reordering (on both Windows and Mac)

User avatar
doublemax
Moderator
Moderator
Posts: 14597
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Reorder column, Resize column events

Post by doublemax » Mon Jan 25, 2016 1:01 pm

I know this is not good, but I didn't find other good way to get wxHeaderCtrl window.
wxHeaderCtrlEvent derives from wxCommandEvent, this means it propagates upwards in the window hierarchy. I think you could have caught the event at wxDataViewCtrl level.
wxEVT_HEADER_END_REORDER event is fired before the actual update in UI.
That is because the event can be Veto()ed, in that case the reordering would not happen. You can use wxEvtHandler::CallAfter() to call any other method asynchronously when the current event processing is done.
http://docs.wxwidgets.org/trunk/classwx ... 50b3719519
Use the source, Luke!

Anil8753
Experienced Solver
Experienced Solver
Posts: 81
Joined: Sat Jan 16, 2016 5:57 am

Re: Reorder column, Resize column events

Post by Anil8753 » Mon Jan 25, 2016 2:16 pm

1. I am not able to catch the wxHeaderCtrl events in wxDataViewCtrl. So has to stick to my hack. :(

2. Tried second one, working :)
I got another solution. I handled the wxIdleEvent of wxHeaderCtrl, This also processed after wxEVT_HEADER_END_RESIZE and wxEVT_HEADER_END_REORDER are processed.

What I did is:

Code: Select all

void DataViewCtrl::OnColumnReordered(wxHeaderCtrlEvent& evt)
{
    m_colsDirty = true;
    evt.Skip();
}

void DataViewCtrl::OnHeaderIdle(wxIdleEvent& evt)
{
    if (m_colsDirty)
    {
        // My code goes here ...

        m_colsDirty = false;
    }

    evt.Skip();
}

Now I got two ways to solve it. Could please suggest me, which one is reliable.

User avatar
doublemax
Moderator
Moderator
Posts: 14597
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Reorder column, Resize column events

Post by doublemax » Mon Jan 25, 2016 2:23 pm

Now I got two ways to solve it. Could please suggest me, which one is reliable.
The CallAfter() version has the advantage that the method is called only when needed, while the IDLE processing happens all the time. But i think either solution is fine.
Use the source, Luke!

Post Reply