Listview column width

Purdue2379
03-26-2003, 12:30 PM
Can someone show me how to set the column width in a Listview?


ListView1.View = lvwReport 'Set The Listview1 View so Columns/Headers can be viewed
ListView1.ColumnHeaders.Add , , "SCAC"
ListView1.ColumnHeaders.Add , , "Last Feed"

I can't get the above code to work when I add a width. The listview is blank when code is run.


I would appreciate any suggestions.

Thanks

GMan_NC
03-26-2003, 12:44 PM
Make sure your ListView.View property is set to 3 - lvwReport

BankCop
03-27-2003, 09:05 PM
Can someone show me how to set the column width in a Listview?


ListView1.View = lvwReport 'Set The Listview1 View so Columns/Headers can be viewed
ListView1.ColumnHeaders.Add , , "SCAC"
ListView1.ColumnHeaders.Add , , "Last Feed"

I can't get the above code to work when I add a width. The listview is blank when code is run.


I would appreciate any suggestions.

Thanks

Here's a module that includes two subs to resize the headers in a listview and disable the headers so they don't act like buttons.



Option Explicit

Private Const GWL_STYLE = (-16)
Private Const HDS_BUTTONS = &H2

Public Const LVM_FIRST = &H1000
Public Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30)
Public Const LVSCW_AUTOSIZE = -1
Public Const LVSCW_AUTOSIZE_USERHEADER = -2
Public Const LVM_GETHEADER = (LVM_FIRST + 31)

Declare Function SendMessage Lib "user32.dll" Alias _
"SendMessageA" (ByVal hwnd As Long, _
ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long


Public Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Sub ResizeHeader(bJunk As Boolean, lstv As ListView)
'===================================================================== =======
'== Procedure: ResizeHeader
'== Date Created: 4/13/2002
'== Purpose: Makes headers in listview control fit the width of the control
'== Last Modified: Never
'== Modification History
'== Date By Change
'----------------------------------------------------------------------------
'
'
'===================================================================== =======

Dim lColumn As Long
Dim lCounter As Long

lCounter = 0
For lColumn = lCounter To lstv.ColumnHeaders.Count - 1
SendMessage lstv.hwnd, _
LVM_SETCOLUMNWIDTH, _
lColumn, _
LVSCW_AUTOSIZE_USERHEADER
Next


End Sub
Public Sub ToggleHeader(lsvhWnd As Long)

'.------------------------------------------------------------------------------
' Source file : - BounceGUI - modListview (Code)
'. Function : - Changes Listview headers to flat instead
'. of 3-D style
'. Parameters : lsvhWnd As Long (The window handle of the
'. listview control to be changed)
'. Return code : - N/A
'. Last Changed: 07/25/1999
' Change History Date Change
'.
'.------------------------------------------------------------------------------

Dim hHeader As Long, lStyle As Long

hHeader = SendMessage(lsvhWnd, LVM_GETHEADER, 0, ByVal 0&)

lStyle = GetWindowLong(hHeader, GWL_STYLE)

SetWindowLong hHeader, GWL_STYLE, lStyle Xor HDS_BUTTONS

End Sub

westcard
08-04-2004, 04:22 PM
I am trying to keep users from changing the width of the column headers. I need to be able to determine if they click on the header because i have a option menu popup when they click on it. The reason for not wanting them to be able to change the width is because one of the options is to hide a column... set width = 0. :confused:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum