Try to use this code
HTML Code:
Public Class PMCombo
Inherits System.Windows.Forms.ComboBox
Protected _ReadOnly As Boolean
Protected _OldIndex As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ComponentModel.IContainer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
#End Region
Public Property IsReadOnly() As Boolean
Get
Return _ReadOnly
End Get
Set(ByVal Value As Boolean)
_ReadOnly = Value
If _ReadOnly Then
Me.BackColor = System.Drawing.SystemColors.Control
Else
Me.BackColor = Color.White
End If
End Set
End Property
Public Overrides Property SelectedIndex() As Integer
Get
Return MyBase.SelectedIndex
End Get
Set(ByVal Value As Integer)
_OldIndex = Value
MyBase.SelectedIndex = Value
End Set
End Property
Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
If IsReadOnly Then
Me.SelectedIndex = _OldIndex
Else
MyBase.OnSelectedIndexChanged(e)
End If
End Sub
End Class
Bookmarks