Only attempt to update the sort order if the control has a model attached.

This commit is contained in:
iwbnwif
2017-08-23 00:21:02 +01:00
parent 110505543f
commit 326b76e649

View File

@@ -133,10 +133,12 @@ public:
// TODO: Set the column's view position. // 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; wxString sortColumn;
if ( RestoreValue(wxPERSIST_DVLC_SORT_KEY, &sortColumn) && if ( control->GetModel() &&
sortColumn != "" ) RestoreValue(wxPERSIST_DVLC_SORT_KEY, &sortColumn) &&
sortColumn != "" )
{ {
bool sortAsc = true; bool sortAsc = true;
column = GetColumnByTitle(control, sortColumn); column = GetColumnByTitle(control, sortColumn);
@@ -145,6 +147,8 @@ public:
{ {
RestoreValue(wxPERSIST_DVLC_SORT_ASC, &sortAsc); RestoreValue(wxPERSIST_DVLC_SORT_ASC, &sortAsc);
column->SetSortOrder(sortAsc); column->SetSortOrder(sortAsc);
// Resort the control based on the new sort criteria.
control->GetModel()->Resort(); control->GetModel()->Resort();
} }
} }