AutoSize ListView Column Headers

Category:
Forms and Controls
Type:
Snippets
Difficulty:
Intermediate
Author:
Richard Moss

Version Compatibility: Visual Basic 5

More information:
You can use this function to either autosize a single column header in a ListView control, or all of them at once. Useful when loading variable data. When the function is called, the column will be resized to match the length of the longest line of text in the ListItems collection.

Please note that the column is sized from the control's font, ie the one set from the Font property. So if you have a ListItem object with a long line of text, and it has it's Bold property set, the column may not be resized to show the full text.

Usage:

To resize a single column, use something like this:

LV_AutoSizeColumn ListViewControl, ColumnHeaderObject

To simply autosize all columns, use this:

LV_AutoSizeColumn ListViewControl

Instructions: Copy the declarations and code below and paste directly into your VB project.

Declarations:

Code: