[VB.NET] Recherche d'item dans ComboBox
Bonjour,
D'après le post d'un autre user, j'ai créé une class d'objet pour ajouter ces items à un combobox.
Code:
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
|
Public Class ComboBoxItem
Private _id As Short
Private _nom As String
Sub New(ByVal id As Short)
_id = id
_nom = "COM " & id.ToString
End Sub
Public Property Id() As Short
Get
Return _id
End Get
Set(ByVal Value As Short)
_id = Value
End Set
End Property
Public Property Nom() As String
Get
Return _nom
End Get
Set(ByVal Value As String)
_nom = Value
End Set
End Property
Overrides Function ToString() As String
Return (_nom)
End Function
End Class |
j'ajoute 2 ports COM dispo à mon combo box
Code:
1 2 3
|
Me.cbPortCom.Items.Add(New ComboBoxItem(2))
Me.cbPortCom.Items.Add(New ComboBoxItem(4)) |
Dans mon combox, j'ai bien COM 2 et COM 4.
Maintenant je voudrais vérifier si COM 2 est bien dans mon combo box
Code:
1 2
|
i=Me.cbPortCom.Items.IndexOf(New ComboBoxItem(2)) |
J'ai i=-1 ce qui signifie que l'élement n'est pas trouvé.
Je ne comprend pas trop car l'id est bien "2" et le nom est bien "COM 2". L'objet est donc identique !?
Est ce que mon raisonnement est correct ?