Problem using SortedBindingList

Problem using SortedBindingList

Old forum URL: forums.lhotka.net/forums/t/3862.aspx


Blarm posted on Thursday, November 08, 2007

Iam getting the following error on the line marked as 'LINE WTH ERROR below:

Unable to cast object of type 'ColasInvoicing.Library.CIDocLines' to type 'System.Collections.Generic.IList`1[ColasInvoicing.Library.CIDocLines]'.

I am using the SortedBindingList in my BusinessBase object:
(Code was copied from the post http://forums.lhotka.net/forums/post/14118.aspx by xal (Andres))

    <NonSerialized(), NotUndoable()> _
    Private m_SortedcIDocLines As SortedBindingList(Of CIDocLines)
    Public ReadOnly Property SortedCIDoclines() As SortedBindingList(Of CIDocLines)
        Get
            If m_SortedcIDocLines Is Nothing Then
                m_SortedcIDocLines = New SortedBindingList(Of CIDocLines)(Me.m_cIDocLines) 'LINE WITH ERROR
                m_SortedcIDocLines.ApplySort("DLLine", ComponentModel.ListSortDirection.Ascending)
            End If
            Return m_SortedcIDocLines
        End Get
    End Property


where m_cIDocLines is declared and used:

Private m_cIDocLines As CIDocLines = CIDocLines.NewCIDocLines(Me)

Private Sub FetchChildren(ByVal dr As SafeDataReader)
    dr.NextResult()
    m_cIDocLines = CIDocLines.GetCIDocLines(dr)
    m_cIDocLines.SetParent(Me)
End Sub

and the CIDocLines class is decared as:

<Serializable()> _
Public Partial Class CIDocLines
 Inherits BusinessListBase(Of CIDocLines, CIDocLine)

and the CIDocLine class is declared as:

 <Serializable()> _
 Public Partial Class CIDocLine
  Inherits BusinessBase(Of CIDocLine)

In my asp.net UI I am using:

    Private Function GetCIDocLines() As SortedBindingList(Of CIDocLines)
        Dim obj As CIDocHead = GetCIDocHead()
        If obj IsNot Nothing Then
            Return obj.SortedCIDoclines
        Else
            Return Nothing
        End If
    End Function

Could someone let me know what I am doing wrong.

Thanks,

Bill

 

McManus replied on Thursday, November 08, 2007

Bill,

The type argument of SortedBindingList must be CIDocLine instead of CIDocLines

Cheers,
Herman

Blarm replied on Thursday, November 08, 2007

Thanks very much Herman.

 

Copyright (c) Marimer LLC