目次 †
先頭項目を表示する †
ComboBox1.Items.Add("security")
ComboBox1.SelectedIndex = 0
コンボボックス内を編集できなくさせる †
DropDownStyleプロパティをDropDownListにする。
表示されるものと対応あるデータを持たせる †
ドロップダウンリストに表示される各項目の背景色を制御する †
↓オーナードロー利用によりComboBoxの描画
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| | Private Sub ComboBox1_DrawItem(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles cmbFiles.DrawItem
If e.Index = -1 Then Exit Sub
Dim combo As ComboBox = sender
Dim textBrush As Brush = If(DirectCast(combo.Items(e.Index), [ComboBoxに登録するアイテムの型]).IsXXX, _
Brushes.BlueViolet, Brushes.Black)
Dim text As String = combo.Items(e.Index).ToString
Dim textRect As RectangleF With textRect
.X = e.Bounds.X
.Y = e.Bounds.Y
.Width = e.Bounds.Width
.Height = e.Bounds.Height
End With
e.DrawBackground() e.Graphics.DrawString(text, e.Font, textBrush, textRect) e.DrawFocusRectangle() End Sub
|
↓ComboBoxに登録するデータオブジェクト
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| | Public Class Item
Private name_ As String
Private isXXX_ As Boolean
Public Sub New(ByVal name As String, ByVal isXXX As Boolean)
name_ = name
isXXX_ = isXXX
End Sub
Public ReadOnly Property Name() As String
Get
Return name_
End Get
End Property
Public ReadOnly Property IsXXX() As Boolean
Get
Return isXXX_
End Get
End Property
Public Overrides Function ToString() As String
Return name_
End Function
End Class
|