Bonjour à tous.
Je développe une application sur VB .Net et j'aimerais savoir comment remplir une DataGridView en fonction des éléments choisis dans une ComboBox.
Merci d'avance pour votre aide.
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Imports System.Linq
Public Class Test_Local
#Region "--- Attributs ---"
Private zListeClient As New List(Of ObjPerso) ' Classe ObjPerso définit au bas
#End Region
#Region "--- Propriétés ---"
Public Property ListeClient() As List(Of ObjPerso)
Get
Return Me.zListeClient
End Get
Set(ByVal value As List(Of ObjPerso))
Me.zListeClient = value
End Set
End Property
#End Region
#Region "--- Méthodes ---"
Private Sub Test_Local_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ChargerDomaine()
InitialiseDGV()
End Sub
Public Sub New()
' Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
End Sub
Public Sub ChargerDomaine()
' Liste d'élément
Dim Entite As New ObjPerso
Entite.Nom = "Hoaz"
Entite.Prenom = "Pelloc"
ListeClient.Add(Entite)
Entite = New ObjPerso
Entite.Nom = "Dab"
Entite.Prenom = "Patrick"
ListeClient.Add(Entite)
' Liste du combobox
Me.ComboBox1.Items.Add("")
Me.ComboBox1.Items.Add("Patrick")
Me.ComboBox1.Items.Add("Pelloc")
End Sub
Private Sub InitialiseDGV()
Me.DataGridView1.DataSource = ListeClient
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If (Not (String.IsNullOrEmpty(Me.ComboBox1.Text))) Then
Dim Liste As List(Of ObjPerso) = _
(From EntX As ObjPerso In ListeClient _
Select EntX _
Where EntX.Prenom = Me.ComboBox1.Text).ToList
Me.DataGridView1.DataSource = Liste
End If
End Sub
#End Region
End Class
Public Class ObjPerso
Private zNom As String
Private zPrenom As String
Public Property Nom() As String
Get
Return Me.zNom
End Get
Set(ByVal value As String)
Me.zNom = value
End Set
End Property
Public Property Prenom() As String
Get
Return Me.zPrenom
End Get
Set(ByVal value As String)
Me.zPrenom = value
End Set
End Property
Public Sub New()
End Sub
End Class
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 2 invités
![]() .: Nous contacter :: Flux RSS :: Données personnelles :. ![]() |