|
-
Feb 17th, 2004, 12:51 PM
#1
Thread Starter
New Member
trapping a right click of a column header
Here's the 911:
I need to trap the right click of a columnheader in a control that inherits from Listview. I realize this means overriding the WndProc method and trapping the WM_Notify, which in turn needs to be converted to a NMHDR structure. However, i am having problems with this not returning the right code. Does anyone have any idea how to do it or can at least point me in the right direction. I am currently using Visual Studio 2003 running on Windows XP pro.
-
Feb 17th, 2004, 02:09 PM
#2
i answered your ? on dotnetforums.net , but here ya go.
i spent an hour or so putting this together...
VB Code:
Imports System.Runtime.InteropServices
'/// top of form's code window^^^
Private WithEvents listviewSubclass As SubclassWindow
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
listviewSubclass = New SubclassWindow()
listviewSubclass.IsSubClassed = True
listviewSubclass.AddControl(ListView1)
End Sub
Private Sub listviewSubclass_MyBaseProc(ByVal m As Message) Handles listviewSubclass.MyBaseProc
If m.Msg = _Win32.WM_NOTIFY Then
'/// now we create / fill our structure using Marshal.PtrToStructure...
Dim nh As NMHDR = Marshal.PtrToStructure(m.LParam, GetType(NMHDR))
If nh.code = _Win32.NM_RCLICK Then
MessageBox.Show("Right button Clicked ColumnHeader")
End If
End If
End Sub
'/// after your End Class of form...
Public Class SubclassWindow
Inherits System.Windows.Forms.NativeWindow
Public Event MyBaseProc(ByVal m As Message)
Public IsSubClassed As Boolean = False
Public Sub AddControl(ByVal ctrl As Control)
MyBase.AssignHandle(ctrl.Handle)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If IsSubClassed Then
RaiseEvent MyBaseProc(m)
End If
MyBase.WndProc(m)
End Sub
Public Overrides Sub ReleaseHandle()
MyBase.ReleaseHandle()
End Sub
End Class
Public Enum _Win32 As Integer
WM_NOTIFY = &H4E
NM_RCLICK = -5
End Enum
<StructLayout(LayoutKind.Sequential)> _
Public Structure NMHDR
Public hwndFrom As Integer
Public idfrom As Integer
Public code As Integer
End Structure
hope it helps
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Feb 17th, 2004, 02:15 PM
#3
911? Don't you mean 411? Or do you want the police or emergency services to answer your post?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|