From: Vadim Zeitlin Date: Tue, 6 Nov 2012 23:56:44 +0000 (+0000) Subject: Keep item data in sync with their position in wxEditableListBox. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6b0dfbca1d817c033b10be2713dbb9d1b7ae0863 Keep item data in sync with their position in wxEditableListBox. When swapping the items, we also need to swap their client data and not just their labels. Closes #14800. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72916 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/editlbox.h b/include/wx/editlbox.h index 7820e72764..946fea8a2c 100644 --- a/include/wx/editlbox.h +++ b/include/wx/editlbox.h @@ -89,6 +89,10 @@ protected: DECLARE_CLASS(wxEditableListBox) DECLARE_EVENT_TABLE() + +private: + void SwapItems(long i1, long i2); + }; #endif // wxUSE_EDITABLELISTBOX diff --git a/src/generic/editlbox.cpp b/src/generic/editlbox.cpp index cf5e5d1913..7818c33a5a 100644 --- a/src/generic/editlbox.cpp +++ b/src/generic/editlbox.cpp @@ -370,26 +370,32 @@ void wxEditableListBox::OnEditItem(wxCommandEvent& WXUNUSED(event)) m_listCtrl->EditLabel(m_selection); } -void wxEditableListBox::OnUpItem(wxCommandEvent& WXUNUSED(event)) +void wxEditableListBox::SwapItems(long i1, long i2) { - wxString t1, t2; + // swap the text + wxString t1 = m_listCtrl->GetItemText(i1); + wxString t2 = m_listCtrl->GetItemText(i2); + m_listCtrl->SetItemText(i1, t2); + m_listCtrl->SetItemText(i2, t1); + + // swap the item data + long d1 = m_listCtrl->GetItemData(i1); + long d2 = m_listCtrl->GetItemData(i2); + m_listCtrl->SetItemData(i1, d2); + m_listCtrl->SetItemData(i2, d1); +} + - t1 = m_listCtrl->GetItemText(m_selection - 1); - t2 = m_listCtrl->GetItemText(m_selection); - m_listCtrl->SetItemText(m_selection - 1, t2); - m_listCtrl->SetItemText(m_selection, t1); +void wxEditableListBox::OnUpItem(wxCommandEvent& WXUNUSED(event)) +{ + SwapItems(m_selection - 1, m_selection); m_listCtrl->SetItemState(m_selection - 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); } void wxEditableListBox::OnDownItem(wxCommandEvent& WXUNUSED(event)) { - wxString t1, t2; - - t1 = m_listCtrl->GetItemText(m_selection + 1); - t2 = m_listCtrl->GetItemText(m_selection); - m_listCtrl->SetItemText(m_selection + 1, t2); - m_listCtrl->SetItemText(m_selection, t1); + SwapItems(m_selection + 1, m_selection); m_listCtrl->SetItemState(m_selection + 1, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); }