Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Listview column widths

Status
Not open for further replies.

shadow02

Programmer
Apr 12, 2004
14
Hi yall,

I am using a listview and after people resize the columns to however they like, I want to record those column widths so that the next time they open the form the columns will be in the width they then left them in.

I only need to know how to reference the column width in a listview. The rest I can do myself.

Anyone have any suggestions.

Thanks heaps
Shadow
 
Hi Shadow02,

to find the width of a column in a listview you need to used the listview.columnheaders(index).width property. Call this sub to output the widths of all columns of your listview in a messagebox:

Private Sub PutListviewWidthsInMsgBox(lvObject As ListView)

Dim count As Integer
Dim Message As String

For count = 1 To lvObject.ColumnHeaders.count
Message = Message & "Width of column " & count & ": " & _
lvObject.ColumnHeaders(count).Width & vbCrLf
Next count

MsgBox Message

End Sub

This obviously does not save the width of the columns, but it gives you an idea of how to get to the values that you seek.

when there's too much something is missing
 
You can use the ColumnHeaders property to find the width, like this:

width = ListView1.ColumnHeaders(1).Width


Just remember the columns start at 1 not 0 (made that mistake a few too many times :) )
 
Guys thanks heaps. That will work a treat. One of the annoying thing about ActiveX is finding any information on them and then working out the syntax etc.

Appreciate your time.
Shado
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top