Toggle column in wxDataViewListCtrl

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
Rick
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Sep 02, 2016 12:26 pm

Toggle column in wxDataViewListCtrl

Post by Rick »

Hi,

I'd like to have toggle columns in my dataview that are exclusive.
So I want only one box to be selected in each row (or each column, depends on the use case).
I'm using a wxDataViewListCtrl as in the example here.

I tried catching the EVT_DATAVIEW_ITEM_VALUE_CHANGED but it's still not 100% clean:

Code: Select all

    
OnToggle(wxDataViewEvent& event) {
    if (ignoreEdit) {
        ignoreEdit = false;
        return;
    }
    if (!event.GetItem().IsOk()) return;
    // This event is called before OnSelection so the row
    // actually the row value is never correct unless we click more than once
     // wxDataViewEvent::GetSelection() is always 0
    int row = mList->GetSelectedRow();
    if (row < 0) return;
    int col = event.GetColumn();
    if (col == 2 || col == 3) {
       
        bool val = mList->GetToggleValue(row, col);
        ignoreEdit = true; // ignore the event that's emitted by SetToggleValue()
        mList->SetToggleValue(!val, row, col == 2 ? 3 : 2);
    }
}
I need three consecutive clicks on the same toggle button until the list behaves as expected. Another problem is that when clicking on the toggle button I don't get the correct row as the SelectionEvent is called after the value changed event. Why doesn't the wxDataViewEvent provide proper row/col values (though the column is right here) and how can I achieve the exclusiveness of toggle buttons in the dataview?

I'm using Debian9 and wxWidgets from the repositories (guess it's version 3.0.3, definitely not 3.1!).
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Toggle column in wxDataViewListCtrl

Post by ONEEYEMAN »

Hi,
Can you reproduce the behaviour in the dataview sample?

Thank you.
Rick
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Sep 02, 2016 12:26 pm

Re: Toggle column in wxDataViewListCtrl

Post by Rick »

I would have to change it in order to add the functionality I want to have and that would result in having the same function I've already shown.
Apart from that, the check boxes in the wxDataViewListCtrl of the sample (third tab) don't respond to clicks at all. Which is strange.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Toggle column in wxDataViewListCtrl

Post by ONEEYEMAN »

Hi,
Could you please check which version of wx and (probably more importantly) what version of GTK+ libraries it is linked against?

Thank you.
Rick
Knows some wx things
Knows some wx things
Posts: 33
Joined: Fri Sep 02, 2016 12:26 pm

Re: Toggle column in wxDataViewListCtrl

Post by Rick »

hi,
wx-config --version gives me 3.0.2
wx-config --toolkit gives me gtk2.
That's also what is displayed when I build sample (obviously, as it uses those commands).

The version of my libgtk2 is 2.24.31-2
I assume gtk3 libs don't matter here as gtk 3.0.2 (dunno if 3.0.3 too) uses gtk2 ?
Post Reply