Re: Locking columns




"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


.



Relevant Pages

  • Re: Locking columns
    ... i am using the ListView control to display data from a database. ... > header control, you need to send the ListView an LVM_GETHEADER message. ...
    (microsoft.public.vb.general.discussion)
  • Re: Using Access with VB
    ... Is your question directed at the database part of this task, ... > Is it possible to use a control to display data in an existing MS Access ... > I don't want to manipulate the (lookup) table, just get data from it to ...
    (microsoft.public.vb.database)
  • Re: Global datasets
    ... Sticking with the first method again. ... Populate my DataSet from the Database ... Create another control object instance ... re-instantiating it. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: instant Lisp web application publishing
    ... flow of control (e,g. first log in the user, then show page x, than ... of Lisp if they want) ... flexible database that can be easily mapped into OOP terminology (so you ... Also I don't have a good candidate server to deploy it too. ...
    (comp.lang.lisp)
  • RE: 438 - Object doesnt support this property or method
    ... I created a new database and imported everything from the original. ... Missing is the Reference to the EzFTP control. ... Set con = Application.CurrentProject.Connection ...
    (microsoft.public.access.formscoding)

Loading