Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Populating list objects
Message
De
10/09/2003 03:46:48
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00827157
Message ID:
00827755
Vues:
14
>>You can actually bind the DataSource of a list control directly to the DataReader. However, I think a cleaner method is to populate an ArrayList or SortedList object and bind the DataSource to it.
>
>That was my first thought too, Keith, but how do I associate the DisplayMember and ValueMember with different columns of the ArrayList or SortedList?

For a SortedList, set the DisplayMember property to "Value" and the ValueMember property to "Key". For an ArrayList, set the DisplayMember and ValueMembers to the properties of the object that reflect the Key&Value pair:
Public Class Person

    Private _SSN As String
    Private _Name As String

    Public Property SSN() As String
        Get
            Return _SSN
        End Get
        Set(ByVal Value As String)
            _SSN = Value
        End Set
    End Property

    Public Property Name() As String
        Get
            Return _Name
        End Get
        Set(ByVal Value As String)
            _Name = Value
        End Set
    End Property

    Public Sub New(ByVal SSN As String, ByVal Name As String)
        Me._SSN = SSN
        Me._Name = Name
    End Sub

End Class

Dim People As New ArrayList()
People.Add(New Person("111-11-1111", "John Doe"))
People.Add(New Person("111-11-1112", "Jane Doe"))
In the previous example, you would set the DisplayMember to "Name" and the ValueMember to "SSN".

I'm making the assumption that the Windows Forms controls work like the ASP.NET controls, so I hope this all works for you!
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform