|
Owner Drawを使うとよいかと思います。
サンプル:
Public Class Form1
Private _List As List(Of clsItem)
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
_List = New List(Of clsItem) From {
New clsItem() With {.ID = "a", .Name = "aaa"},
New clsItem() With {.ID = "b", .Name = "bbb"},
New clsItem() With {.ID = "c", .Name = "ccc"}
}
ComboBox1.DataSource = _List
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "ID"
ComboBox1.DrawMode = DrawMode.OwnerDrawFixed
End Sub
Private Sub ComboBox1_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox1.DrawItem
Dim itm = TryCast(ComboBox1.Items(e.Index), clsItem)
If itm Is Nothing Then
Exit Sub
End If
Dim TextDraw = String.Format("{0} - {1}", itm.ID, itm.Name)
e.DrawBackground()
e.Graphics.DrawString(TextDraw, ComboBox1.Font, Brushes.Black, e.Bounds)
e.DrawFocusRectangle()
End Sub
End Class
Public Class clsItem
Public Property ID As String
Public Property Name As String
Public Overrides Function ToString() As String
Return Name
End Function
End Class
|