Try this:
Imports System.Runtime.InteropServices
Public Class ListViewEx
Inherits ListView
Public Const WM_USER As Integer = &H400
Public Const WM_NOTIFY As Integer = &H4E
Public Const OCM__BASE As Integer = WM_USER + &H1C00
Public Const OCM_NOTIFY As Integer = OCM__BASE + WM_NOTIFY
Public Const LVN_FIRST As Integer = 0 - 100
Public Const LVN_ITEMCHANGING As Integer = LVN_FIRST - 0
Public Const LVIF_STATE As Integer = &H8
Public Const LVIS_SELECTED As Integer = &H2
<StructLayout(LayoutKind.Sequential)> Public Structure NMHDR
Public hwndFrom As IntPtr
Public idFrom As Integer
Public code As Integer
End Structure
<StructLayout(LayoutKind.Sequential)> Public Structure POINT
Public x As Integer
Public y As Integer
End Structure
<StructLayout(LayoutKind.Sequential)> Public Structure NMLISTVIEW
Public hdr As NMHDR
Public iItem As Integer
Public iSubItem As Integer
Public uNewState As Integer
Public uOldState As Integer
Public uChanged As Integer
Public ptAction As POINT
Public lParam As Integer
End Structure
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = OCM_NOTIFY Then
Dim nm As NMHDR = CType(m.GetLParam(GetType(NMHDR)), NMHDR)
If nm.code = LVN_ITEMCHANGING Then
Dim nmlv As NMLISTVIEW =
CType(m.GetLParam(GetType(NMLISTVIEW)), NMLISTVIEW)
If nmlv.uChanged And LVIF_STATE Then
If nmlv.iItem = 0 Then
If nmlv.uNewState And LVIS_SELECTED Then
m.Result = New IntPtr(1)
Exit Sub
End If
End If
End If
End If
End If
MyBase.WndProc(m)
End Sub
End Class
/claes
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:#v*************@TK2MSFTNGP10.phx.gbl...
okey, seems a bit tricky to me... I'm a VB junkie and C# for me is
strange:)
/Lars
"Claes Bergefall" <cl*************@online.nospam> skrev i meddelandet
news:uM**************@TK2MSFTNGP12.phx.gbl... Handle the LVN_ITEMCHANGING and return true to prevent the selection
This should give you some help:
http://groups.google.se/groups?selm=...280a%40phx.gbl
/claes
"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:#k**************@TK2MSFTNGP11.phx.gbl... Can I make a row in a list view NONE selectable or disabled or something?
/Lars