From 326b76e649252258e7682e12961f2fbc0930541e Mon Sep 17 00:00:00 2001 From: iwbnwif Date: Wed, 23 Aug 2017 00:21:02 +0100 Subject: [PATCH] Only attempt to update the sort order if the control has a model attached. --- include/wx/persist/dataview.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/include/wx/persist/dataview.h b/include/wx/persist/dataview.h index 1394ec7289..d0a1ad622f 100644 --- a/include/wx/persist/dataview.h +++ b/include/wx/persist/dataview.h @@ -133,10 +133,12 @@ public: // TODO: Set the column's view position. } - // Restore the sort key and order. + // Restore the sort key and order if there is a valid model and sort + // criteria. wxString sortColumn; - if ( RestoreValue(wxPERSIST_DVLC_SORT_KEY, &sortColumn) && - sortColumn != "" ) + if ( control->GetModel() && + RestoreValue(wxPERSIST_DVLC_SORT_KEY, &sortColumn) && + sortColumn != "" ) { bool sortAsc = true; column = GetColumnByTitle(control, sortColumn); @@ -145,6 +147,8 @@ public: { RestoreValue(wxPERSIST_DVLC_SORT_ASC, &sortAsc); column->SetSortOrder(sortAsc); + + // Resort the control based on the new sort criteria. control->GetModel()->Resort(); } }