Re: Locking columns
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Sat, 24 Dec 2005 17:18:52 -0500
"Mo" <Mo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:EBFB64AE-4C34-469C-899D-968A44D2ACF6@xxxxxxxxxxxxxxxx
> Hi, i am using the ListView control to display data from a database. the
> problem i am having is to restrict users from changing the column sizes
> when
> the program runs. hwo do i do this?
>
The way I would recommend doing this is to subclass the listview's
columnheader and eat the WM_SETCURSOR message. To get the handle of the
header control, you need to send the ListView an LVM_GETHEADER message.
Here's how to do that:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
Private Const LVM_FIRST As Long = &H1000&
Private Const LVM_GETHEADER As Long = LVM_FIRST + 31
'Get handle to Header control
hHeader = SendMessage(ListView.hwnd, LVM_GETHEADER, 0&, ByVal 0&)
Now that you have the hwnd, you can subclass it. In your winproc function,
you'd have something like this:
Private Function WndProcHeader(ByVal hwnd As Long, ByVal uMsg As Long, ByVal
wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_SETCURSOR
'If not allowing columns to be resized, return 1 for this
message
'and don't call the default window proc. This also prevents
'the mouse pointer from changing to the "resize" cursor
If bAllowColumnResize Then
WndProcHeader = CallWindowProc(lpfnOldWinProc, hwnd,
uMsg, wParam, lParam)
Else
WndProcHeader = 1
End If
There is another way that doesn't involve subclassing. Unfortunately, I
don't recall what it is right now. I do remember why I don't use it: the
mouse pointer still changes to the resize cursor, which could confuse users.
> Another problem is when clicking twice in quick sucession, the first
> column
> (the product code) can be changed by the user - although this change does
> not
> update the database. so when you run the program again, the default values
> are back. how do i stop users from changing this value?
>
Set the ListView's LabelEdit property to 1 - lvwManual. With that setting to
the property, you must call the StartLabelEdit method to edit the column
data.
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: Locking columns
- From: David J Mark
- Re: Locking columns
- Prev by Date: Re: find the Inverse Log of a number
- Next by Date: Re: Treeview help
- Previous by thread: Treeview help
- Next by thread: Re: Locking columns
- Index(es):
Relevant Pages
|
Loading