Adding Enabled Property to a ListViewItem

I have a list view and need certain items within that view to be disabled, ie grayed out and the check value cannot be changed.

I created a new class called ExtListViewItem which inherits ListViewItem. All it does it change the forecolor of the text to gray if enabled is set to false:

Public Class ExtListViewItem
    Inherits ListViewItem

    Private _Enabled As Boolean

    Public Property Enabled() As Boolean
        Get
            Enabled = _Enabled
        End Get
        Set(ByVal Value As Boolean)
            _Enabled = Value
            If _Enabled = False Then
                Me.ForeColor = Color.Gray
            Else
                Me.ForeColor = Color.Black
            End If
        End Set
    End Property

End Class

Now I need to stop the check event from firing if enabled is set to false on the ListView. The only event I can find to override that relates to the checking is:

Protected Overrides Sub OnItemCheck(ByVal ice As System.Windows.Forms.ItemCheckEventArgs)

I can't work out how to do it with this event. It's almost like you need a OnBeforeItemCheck.

Does anyone know how I can achive this?
jofesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GilesBathgateCommented:
if Not _Enabled then
   ice.NewValue = CheckState.Unchecked
End if

Does that work?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jofesAuthor Commented:
Thanks that helped me sort it, don't know why I wasn't thinking straight :-)

The onItemCheck event is actually on ListView and not ListViewItem so overrode it as follows:

    Protected Overrides Sub OnItemCheck(ByVal ice As System.Windows.Forms.ItemCheckEventArgs)
        Try
            If CType(Me.Items.Item(ice.Index), ExtListViewItem).Enabled = False Then
                ice.NewValue = CheckState.Checked
            End If
        Catch ex As Exception

        End Try
    End Sub

I wanted disabled items to checked, as they are mandatory. Thanks for the help

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.