Added dedicated command binding of HasPage tab of DVC sample so that the radio button column has always exactly one cell checked. Before this fix this tab was incorrectly bound to the same function that controlled the ListCtrl in the third tab.

This commit is contained in:
Jorge Moraleda
2020-04-20 17:11:24 -07:00
parent ede053def6
commit e25d869168

View File

@@ -170,6 +170,9 @@ private:
enum Lang { Lang_English, Lang_French };
void FillIndexList(Lang lang);
// HasValue page.
void OnHasValueValueChanged(wxDataViewEvent& event);
wxNotebook* m_notebook;
@@ -1038,7 +1041,7 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
lc->AppendItem( data );
}
lc->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &MyFrame::OnListValueChanged, this);
lc->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &MyFrame::OnHasValueValueChanged, this);
}
break;
}
@@ -1772,3 +1775,45 @@ void MyFrame::OnIndexListSelectionChanged(wxDataViewEvent& event)
wxLogMessage("Selected week day: %s", weekday);
}
// ----------------------------------------------------------------------------
// MyFrame - event handlers for the HasValue (wxDataViewListCtrl) page
// ----------------------------------------------------------------------------
void MyFrame::OnHasValueValueChanged(wxDataViewEvent& event)
{
// Ignore changes coming from our own SetToggleValue() calls below.
if ( m_eventFromProgram )
{
m_eventFromProgram = false;
return;
}
wxDataViewListCtrl* const lc = static_cast<wxDataViewListCtrl*>(m_ctrl[Page_HasValue]);
const int columnToggle = 1;
// Handle selecting a radio button by unselecting all the other ones.
if ( event.GetColumn() == columnToggle )
{
const int rowChanged = lc->ItemToRow(event.GetItem());
if ( lc->GetToggleValue(rowChanged, columnToggle) )
{
for ( int row = 0; row < lc->GetItemCount(); ++row )
{
if ( row != rowChanged )
{
m_eventFromProgram = true;
lc->SetToggleValue(false, row, columnToggle);
}
}
}
else // The item was cleared.
{
// Explicitly check it back, we want to always have exactly one
// checked radio item in this column.
m_eventFromProgram = true;
lc->SetToggleValue(true, rowChanged, columnToggle);
}
}
}