wxListCtrl sizing and vertical scrollbar

314 views
Skip to first unread message

Fulvio Senore

unread,
May 28, 2012, 4:56:01 AM5/28/12
to wx-users
I am using a wxListCtrl in report mode to show some data, and I have
written some code to make sure that the columns completely fill the
control's width.

In my code I call wxListCtrl::GetClientSize() to know the available
width, then I resize the columns accordingly.

This works well under Windows, but I have a problem with GTK: if the
list control contains a lot of rows it shows a vertical scroll bar but
GetClientSize() still returns the same width. As a result the last
column is not completely visible because the sizing code does not take
in account the scroll bar size.

This is not a problem under Windows where GetClientSize() returns a
smaller width when the scroll bar is visible.

How can I know the available width for the list control columns?

Thank in advance.

Fulvio Senore

Vadim Zeitlin

unread,
May 28, 2012, 8:58:42 AM5/28/12
to wx-u...@googlegroups.com
On Mon, 28 May 2012 10:56:01 +0200 Fulvio Senore wrote:

FS> In my code I call wxListCtrl::GetClientSize() to know the available
FS> width, then I resize the columns accordingly.
FS>
FS> This works well under Windows, but I have a problem with GTK: if the
FS> list control contains a lot of rows it shows a vertical scroll bar but
FS> GetClientSize() still returns the same width.

I think this is because the scrollbars are actually used with the embedded
wxListMainWindow and not wxListCtrl itself. Try using GetViewRect() instead.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

Fulvio Senore

unread,
May 28, 2012, 10:01:41 AM5/28/12
to wx-u...@googlegroups.com

Il 28/05/2012 14.58, Vadim Zeitlin ha scritto:
> I think this is because the scrollbars are actually used with the embedded
> wxListMainWindow and not wxListCtrl itself. Try using GetViewRect() instead.
>

I did not test it because the docs write:

"Note that this function only works in the icon and small icon views,
not in list or report views (this is a limitation of the native Win32
control)."

and I am using the control in report mode.

Anyway, I tested it and it did not work. Under Windows it reported a
larger width than GetClientSize(), and under Linux it reported a rect
sized 4x4.

Vadim Zeitlin

unread,
May 28, 2012, 11:10:34 AM5/28/12
to wx-u...@googlegroups.com
On Mon, 28 May 2012 16:01:41 +0200 Fulvio Senore wrote:

FS> I did not test it because the docs write:
FS>
FS> "Note that this function only works in the icon and small icon views,
FS> not in list or report views (this is a limitation of the native Win32
FS> control)."

Sorry, I forgot about this.

It looks like you need to manually query the main window for its size
then. This is definitely ugly, we should do something about it... But
making GetClientSize() of wxListCtrl itself lie about its size will
probably result in its own problems. You could try forwarding it to
wxListMainWindow and see what happens though.
Reply all
Reply to author
Forward
0 new messages