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'm using Debian9 and wxWidgets from the repositories (guess it's version 3.0.3, definitely not 3.1!).