Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Prevent dragging elements in a ListView control

Total Hit ( 3196)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The ListView control doesn't expose any property that lets you disable the dragging of its elements. To do so, you must trap the WM_NOTIFY message that the ListView control sends its parent form when the drag operation begins, and "eat" it. Using the MSGHOOK.DLL subclassing library it's easy to accomplish it:

Click here to copy the following block
' REQUIRES THE MSGHOOK.DLL LIBRARY

Const WM_NOTIFY = &H4E
Const LVN_FIRST = -100&
Const LVN_BEGINDRAG = (LVN_FIRST - 9)

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As _
  Any, source As Any, ByVal bytes As Long)

Private Type NMHDR
  hwndFrom As Long
  idFrom As Long
  code As Long
End Type

Dim WithEvents FormHook As MsgHook

Private Sub Form_Load()
  ' start subclassing the current form
  Set FormHook = New MsgHook
  FormHook.StartSubclass Me

  ' fill the ListView1 control with data
  ' ... (omitted) ...
End Sub

' this event fires when the form is sent a message

Private Sub FormHook_BeforeMessage(uMsg As Long, wParam As Long, lParam As Long, _
  retValue As Long, Cancel As Boolean)
  
  ' the ListView might be notifying something to its parent form
  If uMsg = WM_NOTIFY Then
    ' copy the MNHDR structure pointed
    ' to by lParam to a local UDT
    Dim nmh As NMHDR
    CopyMemory nmh, ByVal lParam, Len(nmh)

    ' check whether the notification is from the ListView1 control
    ' and whether it's the beginning of a drag operation
    If nmh.hwndFrom = ListView1.hWnd And nmh.code = LVN_BEGINDRAG Then
      ' yes, cancel this operation
      retValue = 1
      Cancel = True
    End If
  End If
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.