Link to home
Start Free TrialLog in
Avatar of JRockFL
JRockFLFlag for United States of America

asked on

Serialize collecion

I have a collection class that inherits from collectionbase and also implements ComponentModel.IBindingList

I'm trying to make this collection serializable by get this message at runtime

Type 'System.ComponentModel.PropertyDescriptor' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

I tried to add serializabe and nonserializble to all  of the propeties from the ibinding list implementation but get this compile error

Attribute 'SerializableAttribute' cannot be applied to 'SortProperty' because the attribute is not valid on this declaration type.

Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here was my test code:
XmlSerializer serializer = new XmlSerializer(typeof(TestCollection));

using (FileStream outFile = new FileStream("test.xml", FileMode.Create))
{
    serializer.Serialize(outFile, this.coll);
}

Open in new window

Avatar of JRockFL

ASKER

thank you for your reply, mine is just about exact except i decorated with the class wth  <Serializable()> _
Then I decorated the ibindinglist implementation properties with non serializable attribute
Wouldn't you want those properties to be serialized?
The NonSerialized attribute only applies to field members anyways--it is not valid to decorate a property with NonSerialized.
Avatar of JRockFL

ASKER

Maybe in the future, but not right now. Oh ok, I didnt know that about the NonSerialized, thank you.
It looks like there must be something else in my code that is causing the problem then.
Is it possible to post the code for you collection as well as the code where you attempt to serialize it?
Avatar of JRockFL

ASKER

sure hold on
Avatar of JRockFL

ASKER

<Serializable()> _
    Public Class PurchaseOrderLineItemCollection
        Inherits CollectionBase
        Implements ComponentModel.IBindingList
   
    #Region "Private Fields"
   
        Private CurrentSortDirection As System.ComponentModel.ListSortDirection
        Private CurrentSortProperty As System.ComponentModel.PropertyDescriptor
        Private ApplySecondarySort As Boolean = True
        Private _dp As Rockenbach.Data.DataProvider
   
    #End Region
   
    #Region "Public Properties"
   
        ''' <summary>
        ''' The default readonly property for PurchaseOrderLineItem
        ''' </summary>
        ''' <param name="index"></param>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Default Public ReadOnly Property Item(ByVal index As Integer) As Entities.PurchaseOrderLineItem
            Get
                Return CType(list(index), Entities.PurchaseOrderLineItem)
            End Get
        End Property
   
    #End Region
   
    #Region "Constructors"
   
        ''' <summary>
        ''' Creates a new instace of the PurchaseOrderLineItem collection
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub New()
            _dp = New Rockenbach.Data.DataProvider()
        End Sub
   
        ''' <summary>
        ''' Creates a new instace of the PurchaseOrderLineItem collection with the provided DataProvider
        ''' </summary>
        ''' <param name="dp"></param>
        ''' <remarks></remarks>
        Public Sub New(ByVal dp As Rockenbach.Data.DataProvider)
            _dp = dp
        End Sub
   
    #End Region
   
    #Region "Public Methods"    
   
         ''' <summary>
        ''' Sorts the collection by property name
        ''' </summary>
        ''' <param name="PropertyName"></param>
        ''' <param name="Direction"></param>
        ''' <remarks></remarks>
        Public Sub Applysort(ByVal PropertyName As String, ByVal Direction As System.ComponentModel.ListSortDirection)
            Dim pdc As ComponentModel.PropertyDescriptorCollection = ComponentModel.TypeDescriptor.GetProperties(GetType(Entities.PurchaseOrderLineItem))
            ApplySort(pdc(PropertyName), Direction)
        End Sub

        ''' <summary>
        ''' Sorts the collection by property
        ''' </summary>
        ''' <param name="property"></param>
        ''' <param name="direction"></param>
        ''' <remarks></remarks>
        Public Sub ApplySort(ByVal [property] As System.ComponentModel.PropertyDescriptor, ByVal direction As System.ComponentModel.ListSortDirection) Implements System.ComponentModel.IBindingList.ApplySort
            InnerList.Sort(New Controls.PropertyComparer([property], direction))
            RaiseEvent ListChanged(Me, New ComponentModel.ListChangedEventArgs(ComponentModel.ListChangedType.Reset, -1))

            If ApplySecondarySort Then
                If Not IsNothing(CurrentSortProperty) Then
                    Dim i As Int16
                    Dim StartPos As Int16 = 0
                    Dim pc1 As New Controls.PropertyComparer([property], direction)
                    Dim pc2 As New Controls.PropertyComparer(CurrentSortProperty, CurrentSortDirection)
                    For i = 1 To CShort(Me.Count - 1)
                        If pc1.Compare(Me(i - 1), Me(i)) <> 0 Then
                            InnerList.Sort(StartPos, i - StartPos, pc2)
                            StartPos = i
                        End If
                    Next
                    InnerList.Sort(StartPos, Me.Count - StartPos, pc2)
                End If
            End If

            CurrentSortProperty = [property]
            CurrentSortDirection = direction
            ApplySecondarySort = True

        End Sub  
       
        ''' <summary>
        ''' Loads a collection of PurchaseOrderLineItem objects
        ''' </summary>
        ''' <remarks></remarks>
        Public Sub Load()
            Dim criteria As Criteria.PurchaseOrderLineItemCriteria = Nothing
            Load(criteria)
        End Sub
   
        ''' <summary>
        ''' Loads a collection of PurchaseOrderLineItem objects based on criteria
        ''' </summary>
        ''' <param name="criteria"></param>
        ''' <remarks></remarks>
        Public Sub Load(ByVal criteria As Rockenbach.Data.Criteria)
            Dim hsh As New Hashtable()
            Dim reader As SqlDataReader
   
            If Not criteria Is Nothing Then
                If criteria.Where <> String.Empty Then
                    hsh.Add("@Where", criteria.Where)
                End If
   
                If criteria.OrderBy <> String.Empty Then
                    hsh.Add("@OrderBy", criteria.OrderBy)
                End If
            End If
   
            Try
                reader = _dp.ExecuteReader("dbo._PurchaseOrderLineItems_Collection", hsh)
                If Not reader Is Nothing And Not reader.IsClosed Then
                    While reader.Read()
                        Dim objPurchaseOrderLineItem As New Entities.PurchaseOrderLineItem
                        If Not reader.IsDBNull(0) Then
                            objPurchaseOrderLineItem.PurchaseOrderLineItemID = reader.GetInt32(0)
                        End If
                        If Not reader.IsDBNull(1) Then
                            objPurchaseOrderLineItem.PurchaseOrderID = reader.GetInt32(1)
                        End If
                        If Not reader.IsDBNull(2) Then
                            objPurchaseOrderLineItem.Item = reader.GetString(2)
                        End If
                        If Not reader.IsDBNull(3) Then
                            objPurchaseOrderLineItem.Description = reader.GetString(3)
                        End If
                        If Not reader.IsDBNull(4) Then
                            objPurchaseOrderLineItem.Quantity = reader.GetInt32(4)
                        End If
                        If Not reader.IsDBNull(5) Then
                            objPurchaseOrderLineItem.Price = reader.GetDecimal(5)
                        End If
                        If Not reader.IsDBNull(6) Then
                            objPurchaseOrderLineItem.CreatedDate = reader.GetDateTime(6)
                        End If
                        If Not reader.IsDBNull(7) Then
                            objPurchaseOrderLineItem.CreatedBy = reader.GetString(7)
                        End If
                        If Not reader.IsDBNull(8) Then
                            objPurchaseOrderLineItem.ModifiedDate = reader.GetDateTime(8)
                        End If
                        If Not reader.IsDBNull(9) Then
                            objPurchaseOrderLineItem.ModifiedBy = reader.GetString(9)
                        End If
   
                        List.Add(objPurchaseOrderLineItem)
                        objPurchaseOrderLineItem = Nothing
                    End While
                    reader.Close()
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Sub
   
   
        ''' <summary>
        ''' Loads a collection of PurchaseOrderLineItem objects based on PurchaseOrderLineItemcriteria object
        ''' </summary>
        ''' <param name="criteria"></param>
        ''' <remarks></remarks>
        Public Sub Load(ByVal criteria As Criteria.PurchaseOrderLineItemCriteria)
            Dim hsh As New Hashtable()
            Dim reader As SqlDataReader
   
            Dim sb As New StringBuilder()            
            Dim whereUsed As Boolean
            Dim i as Integer = 1
            Dim j as Integer = 1
           
            If Not criteria Is Nothing Then
                If criteria.PurchaseOrderLineItemIDIncludeList.Count > 0 Then
                    Dim purchaseOrderLineItemID As System.Int32
                   
                    If Not whereUsed Then
                        sb.Append(" WHERE PurchaseOrderLineItemID IN (")
                        whereUsed = True
                    Else
                        sb.Append(" AND PurchaseOrderLineItemID IN (")
                    End If
                    For Each PurchaseOrderLineItemID In criteria.PurchaseOrderLineItemIDIncludeList
                        sb.Append("'")
                        sb.Append(PurchaseOrderLineItemID)
                        sb.Append("'")
                        If i < criteria.PurchaseOrderLineItemIDIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i +=1  
                    Next                    
                    If whereUsed Then
                        sb.Append(")")
                    End If
                End If
               
                If criteria.PurchaseOrderLineItemIDExcludeList.Count > 0 Then
                    Dim purchaseOrderLineItemID As System.Int32
                   
                    If Not whereUsed Then
                        sb.Append(" WHERE PurchaseOrderLineItemID NOT IN (")
                        whereUsed = True
                    Else
                        sb.Append(" AND PurchaseOrderLineItemID NOT IN (")
                    End If
                    For Each PurchaseOrderLineItemID In criteria.PurchaseOrderLineItemIDExcludeList
                        sb.Append("'")
                        sb.Append(PurchaseOrderLineItemID)
                        sb.Append("'")
                        If j < criteria.PurchaseOrderLineItemIDExcludeList.Count Then
                            sb.Append(", ")
                        End If  
                        j+=1
                    Next                    
                    If whereUsed Then
                        sb.Append(")")
                    End If
                End If
            End If    
   
            i = 1
            j = 1
           
            If Not criteria Is Nothing Then
                If criteria.PurchaseOrderIDIncludeList.Count > 0 Then
                    Dim purchaseOrderID As System.Int32
                   
                    If whereUsed Then
                        sb.Append(" AND PurchaseOrderID IN (")
                    Else
                        sb.Append(" WHERE PurchaseOrderID IN (")
                        whereUsed = True
                    End If
                   
                    For Each PurchaseOrderID In criteria.PurchaseOrderIDIncludeList
                        sb.Append("'")
                        sb.Append(PurchaseOrderID)
                        sb.Append("'")
                        If i < criteria.PurchaseOrderIDIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.PurchaseOrderIDExcludeList.Count > 0 Then
                    Dim purchaseOrderID As System.Nullable(Of System.Int32)
                   
                    If whereUsed Then
                        sb.Append(" AND PurchaseOrderID NOT IN (")
                    Else
                        sb.Append(" WHERE PurchaseOrderID NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each PurchaseOrderID In criteria.PurchaseOrderIDExcludeList
                        sb.Append("'")
                        sb.Append(PurchaseOrderID)
                        sb.Append("'")
                        If j < criteria.PurchaseOrderIDExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.ItemIncludeList.Count > 0 Then
                    Dim item As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND Item IN (")
                    Else
                        sb.Append(" WHERE Item IN (")
                        whereUsed = True
                    End If
                   
                    For Each Item In criteria.ItemIncludeList
                        sb.Append("'")
                        sb.Append(Item)
                        sb.Append("'")
                        If i < criteria.ItemIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.ItemExcludeList.Count > 0 Then
                    Dim item As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND Item NOT IN (")
                    Else
                        sb.Append(" WHERE Item NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each Item In criteria.ItemExcludeList
                        sb.Append("'")
                        sb.Append(Item)
                        sb.Append("'")
                        If j < criteria.ItemExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.DescriptionIncludeList.Count > 0 Then
                    Dim description As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND Description IN (")
                    Else
                        sb.Append(" WHERE Description IN (")
                        whereUsed = True
                    End If
                   
                    For Each Description In criteria.DescriptionIncludeList
                        sb.Append("'")
                        sb.Append(Description)
                        sb.Append("'")
                        If i < criteria.DescriptionIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.DescriptionExcludeList.Count > 0 Then
                    Dim description As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND Description NOT IN (")
                    Else
                        sb.Append(" WHERE Description NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each Description In criteria.DescriptionExcludeList
                        sb.Append("'")
                        sb.Append(Description)
                        sb.Append("'")
                        If j < criteria.DescriptionExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.QuantityIncludeList.Count > 0 Then
                    Dim quantity As System.Int32
                   
                    If whereUsed Then
                        sb.Append(" AND Quantity IN (")
                    Else
                        sb.Append(" WHERE Quantity IN (")
                        whereUsed = True
                    End If
                   
                    For Each Quantity In criteria.QuantityIncludeList
                        sb.Append("'")
                        sb.Append(Quantity)
                        sb.Append("'")
                        If i < criteria.QuantityIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.QuantityExcludeList.Count > 0 Then
                    Dim quantity As System.Nullable(Of System.Int32)
                   
                    If whereUsed Then
                        sb.Append(" AND Quantity NOT IN (")
                    Else
                        sb.Append(" WHERE Quantity NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each Quantity In criteria.QuantityExcludeList
                        sb.Append("'")
                        sb.Append(Quantity)
                        sb.Append("'")
                        If j < criteria.QuantityExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.PriceIncludeList.Count > 0 Then
                    Dim price As System.Decimal
                   
                    If whereUsed Then
                        sb.Append(" AND Price IN (")
                    Else
                        sb.Append(" WHERE Price IN (")
                        whereUsed = True
                    End If
                   
                    For Each Price In criteria.PriceIncludeList
                        sb.Append("'")
                        sb.Append(Price)
                        sb.Append("'")
                        If i < criteria.PriceIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.PriceExcludeList.Count > 0 Then
                    Dim price As System.Nullable(Of System.Decimal)
                   
                    If whereUsed Then
                        sb.Append(" AND Price NOT IN (")
                    Else
                        sb.Append(" WHERE Price NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each Price In criteria.PriceExcludeList
                        sb.Append("'")
                        sb.Append(Price)
                        sb.Append("'")
                        If j < criteria.PriceExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.CreatedDateIncludeList.Count > 0 Then
                    Dim createdDate As System.DateTime
                   
                    If whereUsed Then
                        sb.Append(" AND CreatedDate IN (")
                    Else
                        sb.Append(" WHERE CreatedDate IN (")
                        whereUsed = True
                    End If
                   
                    For Each CreatedDate In criteria.CreatedDateIncludeList
                        sb.Append("'")
                        sb.Append(CreatedDate)
                        sb.Append("'")
                        If i < criteria.CreatedDateIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.CreatedDateExcludeList.Count > 0 Then
                    Dim createdDate As System.DateTime
                   
                    If whereUsed Then
                        sb.Append(" AND CreatedDate NOT IN (")
                    Else
                        sb.Append(" WHERE CreatedDate NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each CreatedDate In criteria.CreatedDateExcludeList
                        sb.Append("'")
                        sb.Append(CreatedDate)
                        sb.Append("'")
                        If j < criteria.CreatedDateExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.CreatedByIncludeList.Count > 0 Then
                    Dim createdBy As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND CreatedBy IN (")
                    Else
                        sb.Append(" WHERE CreatedBy IN (")
                        whereUsed = True
                    End If
                   
                    For Each CreatedBy In criteria.CreatedByIncludeList
                        sb.Append("'")
                        sb.Append(CreatedBy)
                        sb.Append("'")
                        If i < criteria.CreatedByIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.CreatedByExcludeList.Count > 0 Then
                    Dim createdBy As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND CreatedBy NOT IN (")
                    Else
                        sb.Append(" WHERE CreatedBy NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each CreatedBy In criteria.CreatedByExcludeList
                        sb.Append("'")
                        sb.Append(CreatedBy)
                        sb.Append("'")
                        If j < criteria.CreatedByExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.ModifiedDateIncludeList.Count > 0 Then
                    Dim modifiedDate As System.DateTime
                   
                    If whereUsed Then
                        sb.Append(" AND ModifiedDate IN (")
                    Else
                        sb.Append(" WHERE ModifiedDate IN (")
                        whereUsed = True
                    End If
                   
                    For Each ModifiedDate In criteria.ModifiedDateIncludeList
                        sb.Append("'")
                        sb.Append(ModifiedDate)
                        sb.Append("'")
                        If i < criteria.ModifiedDateIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.ModifiedDateExcludeList.Count > 0 Then
                    Dim modifiedDate As System.Nullable(Of System.DateTime)
                   
                    If whereUsed Then
                        sb.Append(" AND ModifiedDate NOT IN (")
                    Else
                        sb.Append(" WHERE ModifiedDate NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each ModifiedDate In criteria.ModifiedDateExcludeList
                        sb.Append("'")
                        sb.Append(ModifiedDate)
                        sb.Append("'")
                        If j < criteria.ModifiedDateExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
            If Not criteria Is Nothing Then
                If criteria.ModifiedByIncludeList.Count > 0 Then
                    Dim modifiedBy As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND ModifiedBy IN (")
                    Else
                        sb.Append(" WHERE ModifiedBy IN (")
                        whereUsed = True
                    End If
                   
                    For Each ModifiedBy In criteria.ModifiedByIncludeList
                        sb.Append("'")
                        sb.Append(ModifiedBy)
                        sb.Append("'")
                        If i < criteria.ModifiedByIncludeList.Count Then
                            sb.Append(", ")
                        End If
                        i+=1
                    Next      
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If
               
                If criteria.ModifiedByExcludeList.Count > 0 Then
                    Dim modifiedBy As System.String
                   
                    If whereUsed Then
                        sb.Append(" AND ModifiedBy NOT IN (")
                    Else
                        sb.Append(" WHERE ModifiedBy NOT IN (")
                        whereUsed = True
                    End If
                   
                    For Each ModifiedBy In criteria.ModifiedByExcludeList
                        sb.Append("'")
                        sb.Append(ModifiedBy)
                        sb.Append("'")
                        If j < criteria.ModifiedByExcludeList.Count Then
                            sb.Append(", ")
                        End If
                        j+=1
                    Next
                   
                    If whereUsed Then
                        sb.Append(")")
                    End If                    
                End If  

            End If
           
           

           
            If sb.Length > 0 Then
                hsh.Add("@Where", sb.ToString())
            End If            
   
            Try
                reader = _dp.ExecuteReader("dbo._PurchaseOrderLineItems_Collection", hsh)
                If Not reader Is Nothing And Not reader.IsClosed Then
                    While reader.Read()
                        Dim objPurchaseOrderLineItem As New Entities.PurchaseOrderLineItem
                        If Not reader.IsDBNull(0) Then
                            objPurchaseOrderLineItem.PurchaseOrderLineItemID = reader.GetInt32(0)
                        End If
                        If Not reader.IsDBNull(1) Then
                            objPurchaseOrderLineItem.PurchaseOrderID = reader.GetInt32(1)
                        End If
                        If Not reader.IsDBNull(2) Then
                            objPurchaseOrderLineItem.Item = reader.GetString(2)
                        End If
                        If Not reader.IsDBNull(3) Then
                            objPurchaseOrderLineItem.Description = reader.GetString(3)
                        End If
                        If Not reader.IsDBNull(4) Then
                            objPurchaseOrderLineItem.Quantity = reader.GetInt32(4)
                        End If
                        If Not reader.IsDBNull(5) Then
                            objPurchaseOrderLineItem.Price = reader.GetDecimal(5)
                        End If
                        If Not reader.IsDBNull(6) Then
                            objPurchaseOrderLineItem.CreatedDate = reader.GetDateTime(6)
                        End If
                        If Not reader.IsDBNull(7) Then
                            objPurchaseOrderLineItem.CreatedBy = reader.GetString(7)
                        End If
                        If Not reader.IsDBNull(8) Then
                            objPurchaseOrderLineItem.ModifiedDate = reader.GetDateTime(8)
                        End If
                        If Not reader.IsDBNull(9) Then
                            objPurchaseOrderLineItem.ModifiedBy = reader.GetString(9)
                        End If
   
                        List.Add(objPurchaseOrderLineItem)
                        objPurchaseOrderLineItem = Nothing
                    End While
                    reader.Close()
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End Sub
   
        ''' <summary>
        ''' Adds a PurchaseOrderLineItem object to the PurchaseOrderLineItemCollection
        ''' </summary>
        ''' <param name="PurchaseOrderLineItem"></param>
        ''' <remarks></remarks>
        Public Sub Add(ByVal PurchaseOrderLineItem As Entities.PurchaseOrderLineItem)
            list.Add(PurchaseOrderLineItem)
        End Sub
   
        ''' <summary>
        ''' Removes a PurchaseOrderLineItem object from the PurchaseOrderLineItemCollection
        ''' </summary>
        ''' <param name="PurchaseOrderLineItem"></param>
        ''' <remarks></remarks>
        Public Sub Remove(ByVal PurchaseOrderLineItem As Entities.PurchaseOrderLineItem)
            list.Remove(PurchaseOrderLineItem)
        End Sub
   
        ''' <summary>
        ''' Returns the a datatable of the PurchaseOrderLineItem collection
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overridable Function ToDataTable() As DataTable
   
            Dim PurchaseOrderLineItem As New Entities.PurchaseOrderLineItem
            Dim t As Type = PurchaseOrderLineItem.GetType()
            Dim pis() As System.Reflection.PropertyInfo = t.GetProperties()
            Dim dt As New DataTable
   
            For i As Integer = 0 To pis.Length - 1
                Dim pi As System.Reflection.PropertyInfo = CType(pis.GetValue(i), System.Reflection.PropertyInfo)
                dt.Columns.Add(pi.Name)
            Next
   
            For Each PurchaseOrderLineItem In Me.List
                Dim row As DataRow = dt.NewRow()
                For i As Integer = 0 To pis.Length - 1
                    Dim pi As System.Reflection.PropertyInfo = CType(pis.GetValue(i), System.Reflection.PropertyInfo)
                    row(i) = pi.GetValue(PurchaseOrderLineItem, Nothing)
                Next
                dt.Rows.Add(row)
            Next
   
            Return dt
        End Function
    #End Region
   
    #Region "ComponentModel.IBindingList Implementation"

        Public Sub AddIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.AddIndex
            Throw New System.NotImplementedException
        End Sub

        Public Function AddNew() As Object Implements System.ComponentModel.IBindingList.AddNew
            Throw New System.NotImplementedException
        End Function

        Public ReadOnly Property AllowEdit() As Boolean Implements System.ComponentModel.IBindingList.AllowEdit
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public ReadOnly Property AllowNew() As Boolean Implements System.ComponentModel.IBindingList.AllowNew
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public ReadOnly Property AllowRemove() As Boolean Implements System.ComponentModel.IBindingList.AllowRemove
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public Function Find(ByVal [property] As System.ComponentModel.PropertyDescriptor, ByVal key As Object) As Integer Implements System.ComponentModel.IBindingList.Find
            Throw New System.NotImplementedException
        End Function

        Public ReadOnly Property IsSorted() As Boolean Implements System.ComponentModel.IBindingList.IsSorted
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public Event ListChanged(ByVal sender As Object, ByVal e As System.ComponentModel.ListChangedEventArgs) Implements System.ComponentModel.IBindingList.ListChanged

        Public Sub RemoveIndex(ByVal [property] As System.ComponentModel.PropertyDescriptor) Implements System.ComponentModel.IBindingList.RemoveIndex
            Throw New System.NotImplementedException
        End Sub

        Public Sub RemoveSort() Implements System.ComponentModel.IBindingList.RemoveSort
            Throw New System.NotImplementedException
        End Sub

        Public ReadOnly Property SortDirection() As System.ComponentModel.ListSortDirection Implements System.ComponentModel.IBindingList.SortDirection
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public ReadOnly Property SortProperty() As System.ComponentModel.PropertyDescriptor Implements System.ComponentModel.IBindingList.SortProperty
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public ReadOnly Property SupportsChangeNotification() As Boolean Implements System.ComponentModel.IBindingList.SupportsChangeNotification
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public ReadOnly Property SupportsSearching() As Boolean Implements System.ComponentModel.IBindingList.SupportsSearching
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

        Public ReadOnly Property SupportsSorting() As Boolean Implements System.ComponentModel.IBindingList.SupportsSorting
            Get
                Throw New System.NotImplementedException
            End Get
        End Property

    #End Region
   
    End Class
Avatar of JRockFL

ASKER

If it is too much, I can do it another way. I justed tried using a generic list of purchaseorderitems and it worked for me.