Possible to disable a Row in ListView?

  • Thread starter Thread starter Lars Netzel
  • Start date Start date
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
 
Hi Lars,

Maybe this is a crazy answer, however why you want this, when you catch the
select in your program and than direct deselect that line, that is something
that a user in my opinion does not even see.

Cor
 
Back
Top