ListView Control - prevent change to column widths

ListView Control - prevent change to column widths

mdhutchinson
Advisor Advisor
2,772 Views
37 Replies
Message 1 of 38

ListView Control - prevent change to column widths

mdhutchinson
Advisor
Advisor
Other than not displaying them, is there a way to prevent the user from changing the column widths when in 'Report' mode?
0 Likes
2,773 Views
37 Replies
Replies (37)
Message 2 of 38

Anonymous
Not applicable
since there is no resize event for a listbox you will probably have to
resource to the windows api for this.

wrote in message news:5434383@discussion.autodesk.com...
Other than not displaying them, is there a way to prevent the user from
changing the column widths when in 'Report' mode?
0 Likes
Message 3 of 38

mdhutchinson
Advisor
Advisor
sorry... this is the Microsoft ListView Control version 6.0
0 Likes
Message 4 of 38

Anonymous
Not applicable
Not easily, and without using the Windows API and
subclassing the control to handle the notifications
that are fired when it happens.

My guess is that it is not easy because there are not
too many legitimate reasons why a user should not
be able to resize columns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5434383@discussion.autodesk.com...
Other than not displaying them, is there a way to prevent the user from changing the column widths when in 'Report' mode?
0 Likes
Message 5 of 38

mdhutchinson
Advisor
Advisor
agreed!!!

I was able to get this control to work well... thus far...
resizing the column is what I want... after I got some test data into the list I can clearly see why I want to resize the columns.
0 Likes
Message 6 of 38

Anonymous
Not applicable
i would guess that the reason your answer is wrong is because you don't
know. its not doable without the windows api. or is it? please let us know!

"Tony Tanzillo" wrote in message
news:5434497@discussion.autodesk.com...
Not easily, and without using the Windows API and
subclassing the control to handle the notifications
that are fired when it happens.

My guess is that it is not easy because there are not
too many legitimate reasons why a user should not
be able to resize columns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5434383@discussion.autodesk.com...
Other than not displaying them, is there a way to prevent the user from
changing the column widths when in 'Report' mode?
0 Likes
Message 7 of 38

Anonymous
Not applicable
Bobo... My answer is not wrong...

Hope you don't have to depend too much
on your 'guessing'.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Bob" wrote in message news:5434541@discussion.autodesk.com...
i would guess that the reason your answer is wrong is because you don't
know. its not doable without the windows api. or is it? please let us know!

"Tony Tanzillo" wrote in message
news:5434497@discussion.autodesk.com...
Not easily, and without using the Windows API and
subclassing the control to handle the notifications
that are fired when it happens.

My guess is that it is not easy because there are not
too many legitimate reasons why a user should not
be able to resize columns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5434383@discussion.autodesk.com...
Other than not displaying them, is there a way to prevent the user from
changing the column widths when in 'Report' mode?
0 Likes
Message 8 of 38

Anonymous
Not applicable
then by all means let's see the real answer mr. genius!

"Tony Tanzillo" wrote in message
news:5435110@discussion.autodesk.com...
Bobo... My answer is not wrong...

Hope you don't have to depend too much
on your 'guessing'.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Bob" wrote in message
news:5434541@discussion.autodesk.com...
i would guess that the reason your answer is wrong is because you don't
know. its not doable without the windows api. or is it? please let us know!

"Tony Tanzillo" wrote in message
news:5434497@discussion.autodesk.com...
Not easily, and without using the Windows API and
subclassing the control to handle the notifications
that are fired when it happens.

My guess is that it is not easy because there are not
too many legitimate reasons why a user should not
be able to resize columns.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5434383@discussion.autodesk.com...
Other than not displaying them, is there a way to prevent the user from
changing the column widths when in 'Report' mode?
0 Likes
Message 9 of 38

Anonymous
Not applicable
"Bob" wrote

>> then by all means let's see the
>> real answer mr. genius!

Provoking someone to educate you through
insults, doesn't work with me, Bobo.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
0 Likes
Message 10 of 38

Anonymous
Not applicable
yeah, i figured you didn't know. so i'll start educating you. here is your
first installment.

Public Const WM_NOTIFY = &H4E
Public Const GWL_WNDPROC = -4

Public lpPrevWndProc As Long
Public gHW As Long

Public Declare Function CallWindowProc Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam 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 Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
(pDest As Any, pSource As Any, ByVal dwLength As Long)

'ListView notifications
Public Enum HD_Notifications
HDN_FIRST = -300&
HDN_LAST = -399&
HDN_GETDISPINFO = (HDN_FIRST - 9)
HDN_BEGINDRAG = (HDN_FIRST - 10) 'Drag operation has begun
HDN_ENDDRAG = (HDN_FIRST - 11) 'Drag operation has ended
HDN_ITEMCLICK = (HDN_FIRST - 2) 'User clicked the control
HDN_ITEMDBLCLICK = (HDN_FIRST - 3) 'User double-clicked the control
HDN_DIVIDERDBLCLICK = (HDN_FIRST - 5) 'User double clicked the divider
area
HDN_ITEMCHANGING = (HDN_FIRST - 0) 'An item is changing
HDN_ITEMCHANGED = (HDN_FIRST - 1) 'An item has changed
HDN_BEGINTRACK = (HDN_FIRST - 6) 'User began dragging a divider
HDN_ENDTRACK = (HDN_FIRST - 7) 'User finished dragging a divider
HDN_TRACK = (HDN_FIRST - 8) 'User is dragging a divider
NM_FIRST = -0& ' (0U- 0U)
NM_CUSTOMDRAW = (NM_FIRST - 12) 'Custom draw request notification
NM_RCLICK = (NM_FIRST - 5) 'User clicked right mouse button in
control
NM_RELEASEDCAPTURE = (NM_FIRST - 16) 'Control is releasing mouse
capture
End Enum

when i think you have had enough time to digest this bit of code i'll post
your next installment.

btw, it's bob. learn it ... Tony!


"Tony Tanzillo" wrote in message
news:5435562@discussion.autodesk.com...
"Bob" wrote

>> then by all means let's see the
>> real answer mr. genius!

Provoking someone to educate you through
insults, doesn't work with me, Bobo.


--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com
0 Likes
Message 11 of 38

Anonymous
Not applicable
hutch, do any of these do the job for you :
http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2006-24,GGLG:en&q=Prevent+ColumnHeader+sizing

I'm not a prolific VB'er but it seeems that the first 2 may suit your
situation.

regards
kwb


wrote in message news:5434383@discussion.autodesk.com...
Other than not displaying them, is there a way to prevent the user from
changing the column widths when in 'Report' mode?
0 Likes
Message 12 of 38

Anonymous
Not applicable
Bobo....

Any idiot can copy commonly-used WinAPI
function import declarations that can be found
in thousands of places on the net and in books,
and paste them into a post here.

So, who do you think you're fooling?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Bob" wrote in message news:5435528@discussion.autodesk.com...
yeah, i figured you didn't know. so i'll start educating you. here is your
first installment.
0 Likes
Message 13 of 38

Anonymous
Not applicable
obviously you, moron. study the code, the next installment will come soon.
unless you have a "brilliant" answer, you have nothing!

Bob

"Tony Tanzillo" wrote in message
news:5435599@discussion.autodesk.com...
Bobo....

Any idiot can copy commonly-used WinAPI
function import declarations that can be found
in thousands of places on the net and in books,
and paste them into a post here.

So, who do you think you're fooling?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Bob" wrote in message
news:5435528@discussion.autodesk.com...
yeah, i figured you didn't know. so i'll start educating you. here is your
first installment.
0 Likes
Message 14 of 38

Anonymous
Not applicable
What does that do?

Regards - Nathan
0 Likes
Message 15 of 38

Anonymous
Not applicable
Obviously this isn't finished yet. Let's see what installment number two will bring.

I'm kind of enjoying what has become the measure of comtempt in this group. Glad to see it hasn't changed in the last decade.

Good luck,

Bob Coward
0 Likes
Message 16 of 38

Anonymous
Not applicable
It is funny that he bagged Tony for saying it can only being done using the WinAPI and subclassing and then posts WinAPI Declarations which on there own means absolutely nothing. I don't hold any hope of a second installment but if it does come it won't be the simple solution he implied there was.

Regards - Nathan
0 Likes
Message 17 of 38

Anonymous
Not applicable
the first installment wasn't complete so it did pretty much nothing.
however, i have posted the second installment. it too is not the complete
solution which will come later.

btw, i never implied the solution would be easy. i think that if you read
tony's posts you might get that impression, but not mine.

wrote in message news:5436237@discussion.autodesk.com...
It is funny that he bagged Tony for saying it can only being done using the
WinAPI and subclassing and then posts WinAPI Declarations which on there own
means absolutely nothing. I don't hold any hope of a second installment but
if it does come it won't be the simple solution he implied there was.

Regards - Nathan
0 Likes
Message 18 of 38

Anonymous
Not applicable
here is your second installment. enjoy!

Public Sub Hook()
'establish hook to capture messages to this window
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub Unhook()
Dim temp As Long
'reset the message handler for this window
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub

Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Dim nmh As NMHDR
Dim nmhd As NMHEADER

Select Case uMsg
Case WM_NOTIFY
'fill the NMHDR struct from the lParam pointer.
'(for any WM_NOTIFY msg, lParam always points to a struct
'which is either the NMHDR struct, or whose 1st member is the
'NMHDR struct)
Call MoveMemory(nmh, ByVal lParam, Len(nmh))

'could combine HDN_BEGINTRACK
'and HDN_DIVIDERDBLCLICK into one
'(i.e.,Case HDN_BEGINTRACK, HDN_DIVIDERDBLCLICK:)
Select Case nmh.code
Case HDN_BEGINTRACK
'User began dragging a divider
Call MoveMemory(nmhd, ByVal lParam, Len(nmhd))

Select Case nmhd.iItem
'Select Case ListView ColumnHeader Index you want to prevent
tracking.
'Note API is 0 based unlike ColumnHeaders collection which is 1
based.
Case 0
'ListView ColumnHeader Index 1 prevent tracking
WindowProc = 1
Exit Function

Case 1
'ListView ColumnHeader Index 2 prevent tracking
WindowProc = 1
Exit Function

Case Else
'other ColumnHeaders allow resizing

End Select

Case HDN_DIVIDERDBLCLICK
'user double clicked the divider area
Call MoveMemory(nmhd, ByVal lParam, Len(nmhd))

Select Case nmhd.iItem
'Select Case ListView ColumnHeader Index
'you want to prevent resizing if the user double clicks on a
Column separator
'Note API is 0 based unlike ColumnHeaders collection which is 1
based
Case 0
'ListView ColumnHeader Index 1
'prevent resizing if the user double clicks on a Column
separator
WindowProc = 1
Exit Function

Case 1
'ListView ColumnHeader Index 2
'prevent resizing if the user double clicks on a Column
separator
WindowProc = 1
Exit Function

Case Else
'other ColumnHeaders allow resizing

End Select
End Select
End Select

'Pass message on to the original window message handler
WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End Function


"Tony Tanzillo" wrote in message
news:5435599@discussion.autodesk.com...
Bobo....

Any idiot can copy commonly-used WinAPI
function import declarations that can be found
in thousands of places on the net and in books,
and paste them into a post here.

So, who do you think you're fooling?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Bob" wrote in message
news:5435528@discussion.autodesk.com...
yeah, i figured you didn't know. so i'll start educating you. here is your
first installment.
0 Likes
Message 19 of 38

Anonymous
Not applicable
heh, bob, Just make sure you pay homage to Galen Nickerson the author of
that ...
http://www.vbcodemagician.dk/tips/cctrls_lvpreventresize.htm

"Bob" wrote in message
news:5436391@discussion.autodesk.com...
here is your second installment. enjoy!

Public Sub Hook()
'establish hook to capture messages to this window
lpPrevWndProc = SetWindowLong(gHW, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Public Sub Unhook()
Dim temp As Long
'reset the message handler for this window
temp = SetWindowLong(gHW, GWL_WNDPROC, lpPrevWndProc)
End Sub

Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Dim nmh As NMHDR
Dim nmhd As NMHEADER

Select Case uMsg
Case WM_NOTIFY
'fill the NMHDR struct from the lParam pointer.
'(for any WM_NOTIFY msg, lParam always points to a struct
'which is either the NMHDR struct, or whose 1st member is the
'NMHDR struct)
Call MoveMemory(nmh, ByVal lParam, Len(nmh))

'could combine HDN_BEGINTRACK
'and HDN_DIVIDERDBLCLICK into one
'(i.e.,Case HDN_BEGINTRACK, HDN_DIVIDERDBLCLICK:)
Select Case nmh.code
Case HDN_BEGINTRACK
'User began dragging a divider
Call MoveMemory(nmhd, ByVal lParam, Len(nmhd))

Select Case nmhd.iItem
'Select Case ListView ColumnHeader Index you want to prevent
tracking.
'Note API is 0 based unlike ColumnHeaders collection which is 1
based.
Case 0
'ListView ColumnHeader Index 1 prevent tracking
WindowProc = 1
Exit Function

Case 1
'ListView ColumnHeader Index 2 prevent tracking
WindowProc = 1
Exit Function

Case Else
'other ColumnHeaders allow resizing

End Select

Case HDN_DIVIDERDBLCLICK
'user double clicked the divider area
Call MoveMemory(nmhd, ByVal lParam, Len(nmhd))

Select Case nmhd.iItem
'Select Case ListView ColumnHeader Index
'you want to prevent resizing if the user double clicks on a
Column separator
'Note API is 0 based unlike ColumnHeaders collection which is 1
based
Case 0
'ListView ColumnHeader Index 1
'prevent resizing if the user double clicks on a Column
separator
WindowProc = 1
Exit Function

Case 1
'ListView ColumnHeader Index 2
'prevent resizing if the user double clicks on a Column
separator
WindowProc = 1
Exit Function

Case Else
'other ColumnHeaders allow resizing

End Select
End Select
End Select

'Pass message on to the original window message handler
WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End Function


"Tony Tanzillo" wrote in message
news:5435599@discussion.autodesk.com...
Bobo....

Any idiot can copy commonly-used WinAPI
function import declarations that can be found
in thousands of places on the net and in books,
and paste them into a post here.

So, who do you think you're fooling?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

"Bob" wrote in message
news:5435528@discussion.autodesk.com...
yeah, i figured you didn't know. so i'll start educating you. here is your
first installment.
0 Likes
Message 20 of 38

Anonymous
Not applicable
Aw, you take all of his fun away!
0 Likes