RecordOrganizer/app/DD-Record-Organizer/ClassCustomComboBox.vb
2017-04-03 13:01:57 +02:00

66 lines
2.3 KiB
VB.net

Public Class CustomComboBox
Inherits ComboBox
Public Sub New()
MyBase.New()
DrawMode = DrawMode.OwnerDrawFixed
End Sub
'Protected Overrides Sub OnEnabledChanged(e As EventArgs)
' 'MyBase.OnEnabledChanged(e)
' If Me.Enabled Then
' Me.DropDownStyle = ComboBoxStyle.DropDown
' Else
' Me.DropDownStyle = ComboBoxStyle.DropDownList
' End If
'End Sub
Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
Dim g As System.Drawing.Graphics = e.Graphics
Dim rect As Rectangle = e.Bounds
If e.Index >= 0 Then
Dim label As String
' Wenn die Items eine Static List ist, wird der String ausgelesen
If (Me.Items(e.Index).GetType() = GetType(String)) Then
label = Me.Items(e.Index).ToString()
Else
'Wenn die Items aus einer Datatable kommen, wird der DisplayMember ausgelesen
Dim rowView As DataRowView = Me.Items(e.Index)
Dim rowCount As Integer = rowView.Row.ItemArray.Count
If rowCount = 1 Then
label = rowView.Item(0)
ElseIf rowCount = 2 Then
label = rowView.Item(1)
End If
End If
If e.State = (DrawItemState.Disabled Or DrawItemState.NoAccelerator Or DrawItemState.NoFocusRect Or DrawItemState.ComboBoxEdit) Then
' DISABLED STATE
g.FillRectangle(New SolidBrush(System.Drawing.SystemColors.Info), rect)
g.DrawString(label, e.Font, Brushes.Black, rect)
e.DrawFocusRectangle()
ElseIf (e.State = (DrawItemState.NoAccelerator Or DrawItemState.NoFocusRect)) Then
' ITEMS NOT IN FOCUS
g.FillRectangle(New SolidBrush(Color.White), rect)
g.DrawString(label, e.Font, Brushes.Black, rect)
e.DrawFocusRectangle()
Else
' ITEMS IN FOCUS
g.FillRectangle(New SolidBrush(System.Drawing.SystemColors.Highlight), rect)
g.DrawString(label, e.Font, Brushes.White, rect)
e.DrawFocusRectangle()
End If
End If
g.Dispose()
End Sub
End Class