Public Class Form1 Private Class ItemPerso Private mValue As String Private mEnabled As Boolean Public Property Value() As String Get Return mValue End Get Set(ByVal value As String) mValue = value End Set End Property Public Property Enabled() As Boolean Get Return mEnabled End Get Set(ByVal value As Boolean) mEnabled = value End Set End Property Public Sub New(ByVal sValue As String, ByVal bEnabled As Boolean) mValue = sValue mEnabled = bEnabled End Sub End Class Private mListOfItems As New List(Of ItemPerso) Private bLoading As Boolean Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For i As Integer = 1 To 300 mListOfItems.Add(New ItemPerso("Ligne " & i.ToString, ((i Mod 2) = 0))) Next bLoading = True ListBox1.DataSource = mListOfItems ListBox1.DisplayMember = "Value" bLoading = False End Sub Private Sub ListBox1_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedValueChanged If ListBox1.SelectedIndex <> -1 And Not bLoading Then With DirectCast(ListBox1.SelectedValue, ItemPerso) If .Enabled Then MessageBox.Show(String.Format("La valeur {0} est sélectionnée", .Value)) Else 'PAS DE CODE, PAS D'ACTION Console.WriteLine("Item {0} désactivé", .Value) End If End With End If End Sub End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question