Fit wxListCtrl columns to largest item

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
giulio_seb
Experienced Solver
Experienced Solver
Posts: 68
Joined: Mon Feb 07, 2022 11:53 am

Fit wxListCtrl columns to largest item

Post by giulio_seb »

I am using wxWidgets 3.1.5 with a C++ code, on MSW 10. I created a wxListCtrl, and I would like the width of each column in the wxListCtrl to be resized to fit the width of the largest item in the column. Here, by 'largest item' I mean the text with the largest width among both the header and the items in the wxListCtrl.

So far, my wxListCtrl is displayed as in the screenshot, which is not what I want: for example the text "moon" in the first item has ben cut and is diplayed at "moo...". Do you know how to achieve this ?

Thank you for your help :D
Attachments
Screenshot 2023-11-16 at 09.21.43.png
Screenshot 2023-11-16 at 09.21.43.png (27.4 KiB) Viewed 252 times
User avatar
doublemax
Moderator
Moderator
Posts: 18704
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Fit wxListCtrl columns to largest item

Post by doublemax »

Set the column width to wxLIST_AUTOSIZE
Use the source, Luke!
giulio_seb
Experienced Solver
Experienced Solver
Posts: 68
Joined: Mon Feb 07, 2022 11:53 am

Re: Fit wxListCtrl columns to largest item

Post by giulio_seb »

This fixes the width to the width of the longest item. Like I said in my post, I want the column to fit the largest width between header and items.
User avatar
doublemax
Moderator
Moderator
Posts: 18704
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Fit wxListCtrl columns to largest item

Post by doublemax »

wxListCtrl only supports wxLIST_AUTOSIZE and wxLIST_AUTOSIZE_USEHEADER. I don't think you can combine the two. You'll have to do the size calculation yourself then.
Use the source, Luke!
giulio_seb
Experienced Solver
Experienced Solver
Posts: 68
Joined: Mon Feb 07, 2022 11:53 am

Re: Fit wxListCtrl columns to largest item

Post by giulio_seb »

Thank you. Is there a way to achieve the same for wxTextCtrl ?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7171
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Fit wxListCtrl columns to largest item

Post by ONEEYEMAN »

Hi,
What do you mean?
wxTextCtrl does not have columns...

Thank you.
Post Reply