ListView auto size to show all items
What I want to create is a list view that will resize itself in order to show all items. Normally I would use AutoSize, but this won't work here. Any other开发者_运维问答 options how can I make ListView expand and shrink to fit all?
You will have to manually calculate your desired height and set it as items are added/removed.
Detecting item addition or removal isn't directly supported - so you'll either need to create your own Add/Remove Item calls for clients to call, or handle LVN_INSERTIEM type messages from WndProc.
Auto-sizing controls are usually trickier to use - as you have to track Min/Max sizes, allow room on the owner, and usually add to an awkward usability point for users. Only do something like this if typical solutions (i.e. scroll bars) truly can't work for your need.
"AutoSize" property is not supported for the "ListView" control. As @JohnArien mentioned, you will have to programmatically re-size your list view control's size according to the number of items available. But be warned that this may not be a good idea in terms of visual appeal of the Form. Your form design might look ugly if you change the size in run time. More over these types of controls are expected to expand their client area within the given size with the help of scroll bars. I would strongly suggest you to reconsider this option.
精彩评论