From f46a5423ae4372b1ebe84231dbd7755962eb8c10 Mon Sep 17 00:00:00 2001 From: oneeyeman1 Date: Tue, 1 Oct 2019 08:05:23 -0500 Subject: [PATCH] Implement autosizing of columns in generic wxListCtrl Autosize the column to fit its contents or its label width if there are no items when its divider is double clicked. This is consistent with wxMSW behaviour and is generally convenient. Closes https://github.com/wxWidgets/wxWidgets/pull/1573 --- src/generic/listctrl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 7e7e679158..4903e3d440 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -1359,6 +1359,15 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event ) event.GetPosition()); } } + else if ( event.LeftDClick() && hit_border ) + { + // Autosize the column when the divider is clicked: if there are + // any items, fit the columns to its contents, otherwise just fit + // it to its label width. + parent->SetColumnWidth(m_column, + parent->IsEmpty() ? wxLIST_AUTOSIZE_USEHEADER + : wxLIST_AUTOSIZE); + } else if (event.Moving()) { bool setCursor;