From 876728f6cda6867fb606dc0b6b58ced2b56936f5 Mon Sep 17 00:00:00 2001 From: Vadym Hrynchyshyn Date: Sun, 22 Feb 2026 10:50:23 +0200 Subject: [PATCH] Restore wxDataViewCtrl columns view positions Previously only saving columns positions was implemented, but they were never restored. Closes #26222. Signed-off-by: Vadym Hrynchyshyn --- include/wx/persist/dataview.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/wx/persist/dataview.h b/include/wx/persist/dataview.h index 950a07660d..1aaa81087c 100644 --- a/include/wx/persist/dataview.h +++ b/include/wx/persist/dataview.h @@ -16,6 +16,8 @@ #include "wx/dataview.h" +#include + // ---------------------------------------------------------------------------- // String constants used by wxPersistentDataViewCtrl. // ---------------------------------------------------------------------------- @@ -95,6 +97,7 @@ public: virtual bool Restore() override { wxDataViewCtrl* const control = Get(); + std::vector order(control->GetColumnCount()); for ( unsigned int col = 0; col < control->GetColumnCount(); col++ ) { @@ -115,7 +118,24 @@ public: if ( RestoreValue(columnPrefix + wxASCII_STR(wxPERSIST_DVC_WIDTH), &width) ) column->SetWidth(width); - // TODO: Set the column's view position. + // Restore the column's view position. + int pos; + if ( RestoreValue(columnPrefix + wxASCII_STR(wxPERSIST_DVC_POS), &pos) ) + { + if ( pos >= 0 && pos < wxSsize(order) ) + order[pos] = column; + } + } + + // Set columns view position. + for ( int i = 0; i < wxSsize(order); ++i ) + { + auto* const column = order[i]; + if ( column && i != control->GetColumnPosition(column) ) + { + control->DeleteColumn(column); + control->InsertColumn(i, column); + } } // Restore the sort key and order if there is a valid model and sort