2 Attachment(s)
[VB6] Lock ListView Columns
This code prevents the specified column(s) of a ListView control from being resized by the user. It does that by subclassing the ListView control and watching for the HDN_BEGINTRACK and HDN_DIVIDERDBLCLICK notification codes. Additionally, it also provides appropriate feedback to the user by displaying the "Unavailable" cursor when the mouse is over the locked column divider. That is done by subclassing the ListView's Header control and handling the WM_SETCURSOR message.
The modLockLVCols.bas file in the attached project below has been inspired by the codes in the following threads:
Preventing certain Listview columns from sizing...
[RESOLVED] Prevent User From Resizing Column Width in ListView
Also included in the attachment is frmLockLVColsDemo.frm:
Re: [VB6] Lock ListView Columns
tnk you very much bonnie very useful
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
Bonnie West
hi...
possible to use this code in a vba userform and listview in VBA for Excel?
Tks.
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
luca90
hi...
possible to use this code in a vba userform and listview in VBA for Excel?
Tks.
Sorry, but I have not tested that code in VBA. :( The Subclass function, however, will let you know if it works there. So, try it and see what happens.
Re: [VB6] Lock ListView Columns
Glad to see that you included visual feedback.
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
dilettante
Glad to see that you included visual feedback.
Yeah, I got that idea from Chris001, who has been wondering how to accomplish that:
Quote:
Originally Posted by
Chris001
Unfortunately I still haven't found a way to hide the double-arrow cursor when moving over a locked column divider. WM_SETCURSOR doesn't 'fire' when the cursor is moved over a column divider.
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
Bonnie West
Sorry, but I have not tested that code in VBA. :( The Subclass function, however, will let you know if it works there. So, try it and see what happens.
HI...
THE CLASS WORK PERFECT ALSO IN VBA FOR deXCEL!!!!!!!!!!!!!!!!!
But i dont like the signal on the cursor...
possible to change with the standard cursor?
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
luca90
THE CLASS WORK PERFECT ALSO IN VBA FOR deXCEL!!!!!!!!!!!!!!!!!
Thanks for testing! :thumb:
Quote:
Originally Posted by
luca90
But i dont like the signal on the cursor...
possible to change with the standard cursor?
Yes. Just add this constant declaration for the standard arrow cursor:
Code:
Private Const IDC_ARROW As Long = 32512
and replace the line:
Code:
m_hCursor = LoadCursorW(0&, IDC_NO)
with:
Code:
m_hCursor = LoadCursorW(0&, IDC_ARROW)
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
Bonnie West
Thanks for testing! :thumb:
Yes. Just add this constant declaration for the
standard arrow cursor:
Code:
Private Const IDC_ARROW As Long = 32512
and replace the line:
Code:
m_hCursor = LoadCursorW(0&, IDC_NO)
with:
Code:
m_hCursor = LoadCursorW(0&, IDC_ARROW)
oPS!
i have 12 column in lv1 and i i filled the array in this mode:
Subclass ListView1.hWnd, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
is this correct?
Why?...
all column are lockhed but the last not(?!), i can enlarge only the column 12.(the column 12 have size (0))
tkx u in other case for code.
perphs i can understand, see here:
http://www.vbforums.com/showthread.p...ns-from-sizing
see post #33
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
luca90
i have 12 column in lv1 and i i filled the array in this mode:
Subclass ListView1.hWnd, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
is this correct?
Why?...
all column are lockhed but the last not(?!), i can enlarge only the column 12.(the column 12 have size (0))
. . .
perphs i can understand, see here:
http://www.vbforums.com/showthread.p...ns-from-sizing
see post #33
I'm sorry, but could you please attach a screenshot of your ListView control here (click the Insert Image button on the editor's toolbar)? Please also state which column(s) of your ListView that you want to be locked.
1 Attachment(s)
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
Bonnie West
I'm sorry, but could you please attach a screenshot of your ListView control here (click the Insert Image button on the editor's toolbar)? Please also state which column(s) of your ListView that you want to be locked.
after the last visible column a just have other 5 columns with size(0) and are hide(are only a service column) not important to show tath.
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
luca90
after the last visible column a just have other 5 columns with size(0) and are hide(are only a service column) not important to show tath.
So, your ListView control has a total of 15 columns, of which 10 are visible and 5 are hidden. Is that right?
I'll ask this again: which column(s) do you want to be locked?
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
Bonnie West
So, your ListView control has a total of 15 columns, of which 10 are visible and 5 are hidden. Is that right?
I'll ask this again: which column(s) do you want to be locked?
So, your ListView control has a total of 15 columns, of which 10 are visible and 5 are hidden. Is that right?
YES!.
which column(s) do you want to be locked?
Only the visible columns (are 10)
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
luca90
Only the visible columns (are 10)
Well, in that case, here's how you would call the Subclass function:
Code:
Subclass ListView1.hWnd, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Remember, the first column has an index of 0. ;)
Re: [VB6] Lock ListView Columns
Thanks very much for this Bonnie!
Just a quick comment... Like luca90 I'm using your code in XL VBA. I've noticed that if any of the locked columns have a width of zero, then the "resize" pointer still shows when hovering between the two (non zero width) columns either side of the zero width column. Not really a problem, as the locking functionality persists.
Once again thank you. Up till now I've had to rely on various form events to trigger a sub which reset all my column widths. Flicker city!
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
Bonnie West
Thanks for testing! :thumb:
Yes. Just add this constant declaration for the
standard arrow cursor:
Code:
Private Const IDC_ARROW As Long = 32512
and replace the line:
Code:
m_hCursor = LoadCursorW(0&, IDC_NO)
with:
Code:
m_hCursor = LoadCursorW(0&, IDC_ARROW)
hi friend, sorry if i post on old th3d
but have prb when exit from form with unload me...
i have see other form are freezed, and ivba ide work not correctlly..
perphs i need to destroyed a object opened from lock listview routine?
in other case the code work!
Re: [VB6] Lock ListView Columns
Quote:
Originally Posted by
luca90
but have prb when exit from form with unload me...
i have see other form are freezed, and ivba ide work not correctlly..
perphs i need to destroyed a object opened from lock listview routine?
Can you post the code in your Form's Unload event? (You're not using the End statement, are you?)
EDIT
Quote:
Originally Posted by
blackworx
Just a quick comment... Like luca90 I'm using your code in XL VBA. I've noticed that if any of the locked columns have a width of zero, then the "resize" pointer still shows when hovering between the two (non zero width) columns either side of the zero width column. Not really a problem, as the locking functionality persists.
This issue turns out to be quite easy to fix (thanks to Krool for suggesting this solution). Just add this constant declaration:
Code:
Private Const HHT_ONDIVOPEN As Long = &H8
And then modify this line:
Code:
If HDHTI.Flags And HHT_ONDIVIDER Then
To:
Code:
If HDHTI.Flags And (HHT_ONDIVIDER Or HHT_ONDIVOPEN) Then
Re: [VB6] Lock ListView Columns
Is there a less statement that will locked the listview column headers?
Re: [VB6] Lock ListView Columns
Do you mean a less complex way of doing it than what Bonnie has posted? Not really... you could do it with a few less lines but you still have to subclass and intercept HDN_BEGINTRACK