Search code examples
c++windowslistreportwxwidgets

wxWidgets, wxListCtrl: How to prevent auto size of column when db-click on divider


[EDITED AT THE END]

I'm always getting stuck on the same problem while writing gui programs with wxWidgets.

When double clicking on the divider in a wxListCtrl with report type between the columns, the column to the left gets resized to the "optimal" width. Of course, in many cases this is a nice feature, but I want to be able to turn that off in some cases.

I'm constantly looking through the bug reports and information blogs from the wxWidgets community and this is a question, which not many have asked already, as far as I can see.

The only thing I once found (can't remember AND find the link anymore) was an answer to a bug report mentioning, that the class wxHeaderctrl does actually own an event called EVT_HEADER_DCLICK(id, func).

After that I looked through the documentation and samples and there was also mentioned, that wxHeaderCtrl is somehow used for listctrl's and other lists. But I just can't find a connection anywhere between these classes, and I still couldn't find a way to prevent the autosizing of the column when double clicking on the divider by playing around with "custom made classes" approaches.

Is there actually a way to do this in a "wxWidgets" way, or do I have to change to another toolkit (or framework)?

Thanks for your recommendation in advance.

More information:

  • Platform: Windows 10
  • Language: C++
  • Compiler: mingw64 v7.3.0
  • Toolkit: wxWidgets v3.0.4

Picture: before db-clicking

enter image description here

Picture: after db-clicking

enter image description here

EDIT (29.04.2018 16:42 | MESZ)

I actually found something after thinking about VZ's answer in other subclasses which use a separated model to view approach (which I was used to from other languages or toolkits)

I now use a wxDataViewCtrl as a view and a wxDataViewListStore as a model. In the control class I can set specific flags for each column which include the matter of resizing and other events.

Thank you for stimulating my thoughts :)


Solution

  • Resizing of the column on double click is the native behaviour of MSW list control and I don't think it's easily possible to prevent it from happening for resizeable items using wx API currently.

    Of course, if the item is not resizeable in the first place, then there is no problem. But if you want to allow the user to resize it but not to do it automatically on double click, you need to write your code in rather unnatural way and handle wxEVT_LIST_COL_DRAGGING events that happen after wxEVT_LIST_COL_END_DRAG ones as these artificial events are only generated when double clicking, and not when dragging normally, and then forcefully resize the column back to its original width. IMO it's too ugly and not worth it, but you should be able to make it work if you really want to.