Public Class DoubleCombo
Inherits Windows.Forms.ComboBox
Private Widths As String
Private HighLight As Color = Color.LightSteelBlue
Private HighLightFore As Color = Color.Black
Sub New()
Me.DrawMode = DrawMode.OwnerDrawFixed
End Sub
Private Sub CustomCombo_DoubleItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MyBase.DrawItem
Dim obj As Object
Dim p As New Pen(Color.Black)
Dim pHighLight As New SolidBrush(HighLightFore)
Dim drv As DataRowView
Dim bru As New SolidBrush(Color.Black)
Dim bruBack As New SolidBrush(HighLight)
Dim bruWhite As New SolidBrush(Color.White)
Dim counter As Integer
Dim counter2 As Integer
Dim splits() As String
Dim s As String
Dim LeftWidth As Integer
Dim RightWidth As Integer
Dim Numeric As Boolean = True
splits = Widths.Split(";")
For Each s In splits
If IsNumeric(s) = False Then
LeftWidth = 64
RightWidth = 64
Numeric = False
End If
Next
If Numeric = True AndAlso splits.Length >= 2 Then
LeftWidth = splits(0)
RightWidth = splits(1)
End If
counter = 0
For Each obj In Me.Items
'White Wash Background
e.Graphics.FillRectangle(bruWhite, 0, counter, LeftWidth, Me.ItemHeight)
e.Graphics.FillRectangle(bruWhite, LeftWidth + 1, counter, RightWidth, Me.ItemHeight)
'Draw Borders
e.Graphics.DrawRectangle(p, 0, counter, LeftWidth, Me.ItemHeight)
e.Graphics.DrawRectangle(p, LeftWidth + 1, counter, RightWidth, Me.ItemHeight)
If Me.SelectedIndex = counter2 Then
'Highlight Selected Item
e.Graphics.FillRectangle(bruBack, 1, counter + 1, LeftWidth - 1, Me.ItemHeight - 1)
e.Graphics.FillRectangle(bruBack, LeftWidth + 2, counter + 1, RightWidth - 1, Me.ItemHeight - 1)
End If
If obj.GetType.ToString = "System.Data.DataRowView" Then
drv = obj
If Me.SelectedIndex = counter2 Then
e.Graphics.DrawString(drv.Item(Me.ValueMember), Me.Font, pHighLight, 2, counter)
e.Graphics.DrawString(drv.Item(Me.DisplayMember), Me.Font, pHighLight, LeftWidth + 2, counter)
Else
e.Graphics.DrawString(drv.Item(Me.ValueMember), Me.Font, bru, 2, counter)
e.Graphics.DrawString(drv.Item(Me.DisplayMember), Me.Font, bru, LeftWidth + 2, counter)
End If
End If
counter += Me.ItemHeight
counter2 += 1
Next
bru.Dispose()
bruBack.Dispose()
bruWhite.Dispose()
p.Dispose()
End Sub
Public Property ItemWidths() As String
Get
Return Widths
End Get
Set(ByVal Value As String)
Widths = Value
End Set
End Property
Public Property HighLightColor() As Color
Get
Return HighLight
End Get
Set(ByVal Value As Color)
HighLight = Value
End Set
End Property
Public Property HighLightForeColor() As Color
Get
Return HighLightFore
End Get
Set(ByVal Value As Color)
HighLightFore = Value
End Set
End Property
End Class