From 7f8f2a9aa3fcc346d1962a7e59dc523db20b7e8e Mon Sep 17 00:00:00 2001 From: DietmarSchwertberger Date: Sun, 10 Apr 2022 15:35:54 +0200 Subject: [PATCH] Fix asserts when changing columns of wxGrid using native header The number of columns has to be changed after updating the m_colAt and m_colWidths arrays, as the native header uses them. This extends the changes of a2d65663a0 (Fix assert when adding columns to wxGrid using native header., 2013-05-31) to inserting and deleting the columns too. See #15225. Closes #22294. --- src/generic/grid.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 450ff9ff7a..98e8e9fe20 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -3473,9 +3473,6 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) int numCols = msg.GetCommandInt2(); m_numCols += numCols; - if ( m_useNativeHeader ) - GetGridColHeader()->SetColumnCount(m_numCols); - if ( !m_colAt.IsEmpty() ) { //Shift the column IDs @@ -3513,6 +3510,11 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) } } + // See comment for wxGRIDTABLE_NOTIFY_COLS_APPENDED case explaining + // why this has to be done here and not before. + if ( m_useNativeHeader ) + GetGridColHeader()->SetColumnCount(m_numCols); + UpdateCurrentCellOnRedim(); if ( m_selection ) @@ -3586,8 +3588,6 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) size_t pos = msg.GetCommandInt(); int numCols = msg.GetCommandInt2(); m_numCols -= numCols; - if ( m_useNativeHeader ) - GetGridColHeader()->SetColumnCount(m_numCols); if ( !m_colAt.IsEmpty() ) { @@ -3620,6 +3620,11 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) } } + // See comment for wxGRIDTABLE_NOTIFY_COLS_APPENDED case explaining + // why this has to be done here and not before. + if ( m_useNativeHeader ) + GetGridColHeader()->SetColumnCount(m_numCols); + UpdateCurrentCellOnRedim(); if ( m_selection )