News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ListView in report mode resize.

Started by xanatose, August 17, 2010, 03:09:41 AM

Previous topic - Next topic

xanatose

How do I determine the optimum size for the last column on a Listview in report mode?
The control is resized at run time.


[EDIT]
By optimum size of last column, I mean a size that does not leave empty space after it, but does not generate a scrollbar.

Twister

I think that size would depend on the layout your application/dialog, the width of the Listview, the length of the elements that are being displayed horizontally.  So it's rough to determine what to do with this much information.

You could use the ListView_ApproximateViewRect Macro to find the current size. Do some calculations off of that to size down the view, and align the last column to the right edge.

EDIT: After thinking about that for a while, there may be a much more simpler method.

xanatose

Basically I have a listview with some static sized columns (for numbers) and the last one variable for strings. I want the last one to resize to the available size of the ListView, not be to short and not be so long that it starts showing the horizontal scrollbar. The ListView control itself is resized when the main window is resized.

I tried using the client rect of the List View to get the width and then just substracting the width of the other columns, but the result is too big (it starts showing the horizontal scrollbar).
I can try trial and error, but  would like to know the right algortihm for finding the optimun width for the last column.

[EDIT]
Never mind, it was a bug on another place of the code. For the curious the steps to do this are:

1. Get the client rect of the list view.
2. Add all the widths of the static sized columns.
3. Substract the added widths from the width of the client rect of the listview.
4. if the result is positive, you have the width to use at the last column.

Gunner

You could use the following message:
LVM_SETCOLUMNWIDTH

with the following:
LVSCW_AUTOSIZE_USEHEADER
QuoteAutomatically sizes the column to fit the header text. If you use this value with the last column, its width is set to fill the remaining width of the list-view control.

    invoke  SendMessage, hLVMainSys, LVM_SETCOLUMNWIDTH, COLUMNINDEXHERE, LVSCW_AUTOSIZE_USEHEADER

I use it and it works well.
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

xanatose

Thank you, is good to know there is an easier way.