Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Binding Datagrids to collection
Message
De
10/01/2007 18:05:36
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Programmation orienté objet
Titre:
Binding Datagrids to collection
Divers
Thread ID:
01184397
Message ID:
01184397
Vues:
71
I bound a datagrid to a collection class I created, and it works fine. Problem is, when I programatically add items to the collection, the datagrid does not reflect that. I tried to rebind the datagrid, but no dice. Any suggestions?
    Public Class Recipients
        Inherits CollectionBase

        Public Sub New()

            'var
            Dim recipient As Recipient

            Try
                recipient = New Recipient("Mike", "1234", "Mike Inc.", "1234 5th St.", "Jesup", "IA", 50648)
                innerlist.Add(recipient)

                recipient = New Recipient("Joe", "4321", "Joe Inc.", "4321 1st St.", "Urbana", "IA", "55555")
                innerlist.Add(recipient)

                recipient = New Recipient("Herky", "5555", "Herky's Hawkeyes", "5555 5th St", "Iowa City", "IA", "54334")
                innerList.Add(recipient)

            Catch ex As Exception
                Throw ex
            End Try
        End Sub

        Public Sub Add(ByVal entry As Recipient)
            InnerList.Add(entry)
        End Sub

        Public Sub Remove(ByVal index As Integer)
            If index < 0 Or index > Me.Count - 1 Then
                Throw New IndexOutOfRangeException
            Else
                InnerList.RemoveAt(index)
            End If
        End Sub

        Default Public Property Item(ByVal index As Integer) As Recipient
            Get
                Return CType(InnerList.Item(index), Recipient)
            End Get
            Set(ByVal Value As Recipient)
                InnerList.Item(index) = Value
            End Set
        End Property

    End Class
 Dim searchColl As Recipients
 searchColl = New Recipients
 DataGrid1.DataSource = searchColl
 searchColl.Add(New Recipient("Mark", "8493", "asdf", "8848 1 St.", "Clear Lake", "IA", "50436"))
Very fitting: http://xkcd.com/386/
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform