Disable custom controls event

I have a custom control that contains a datagrid. On some forms I want the user to be able to double click a cell, but sometimes I dont want that even enabled. Is there a way to disable this? I was thinking maybe pass in a flag telling it whether to do the events code or not. What is the best way to do this?
Who is Participating?
oobaylyConnect With a Mentor Commented:
That's probably the easiest way to do it. Another method would be to use AddHandler & RemoveHandler so that the event is never handled.
  Private m_HandleClick As Boolean
  Public Property HandleClick() As Boolean
      Return m_HandleClick
    End Get
    Set(ByVal value As Boolean)
      If (m_HandleClick = value) Then Return
      m_HandleClick = value
      If (m_HandleClick) Then
        AddHandler grid.Click, AddressOf grid_Click
        RemoveHandler grid.Click, AddressOf grid_Click
      End If
    End Set
  End Property

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.