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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
Public Class Form6
Private Sub Form6_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim dt1 As New DataTable
dt1.Columns.Add("Col1")
dt1.Rows.Add("Val1")
dt1.Rows.Add("Val2")
dt1.Rows.Add("Val3")
dt1.Rows.Add("Val4")
Me.MonComboBebete1.DataSource = dt1
Me.MonComboBebete1.ValueMember = "Col1"
Me.MonComboBebete1.DisplayMember = "Col1"
End Sub
Private Sub MonComboBebete1_dropdownListItemChanged(ByVal value As String) Handles MonComboBebete1.dropdownListItemChanged
Me.TextBox1.Text = value
End Sub
End Class
Public Class MonComboBebete
Inherits ComboBox
Dim idx As Integer = -2
Public Event dropdownListItemChanged(ByVal Value As String)
Public Sub New()
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
End Sub
Private Sub H_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles Me.DrawItem
Try
If e.Index < 0 Then Exit Sub
Dim strValue As String
strValue = CStr(CType(Me.DataSource, DataTable).Rows(e.Index).Item(0))
'
' Couleur de fond : si sélectionné, dégradé, sinon on laisse faire
'
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
Dim backbrush As New _
System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, _
Color.LightBlue, _
Color.DarkBlue, _
System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
e.Graphics.FillRectangle(backbrush, e.Bounds)
If e.Index <> idx Then
RaiseEvent dropdownListItemChanged(strValue)
End If
idx = e.Index
Else
e.DrawBackground()
End If
Dim dtTable As DataTable = CType(Me.DataSource, DataTable)
Dim sngWidth As Single = 0
' Text de la colonne
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
e.Graphics.DrawString(strValue, Me.Font, System.Drawing.Brushes.White, e.Bounds)
Else
e.Graphics.DrawString(strValue, Me.Font, System.Drawing.Brushes.DarkBlue, e.Bounds)
End If
' Focus
e.DrawFocusRectangle()
Catch ex As Exception
MsgBox("erreur")
End Try
End Sub
End Class |
Partager