Strange behaviour of datagridview binded to sortedbindinglist

Strange behaviour of datagridview binded to sortedbindinglist

Old forum URL:

Niemand posted on Tuesday, April 19, 2011

I encountered strange behavior of datagridview:


In the parent object  (invoice) I have a childlist (invoiceitemlist) that I expose through a property like this:

Public ReadOnly Property InvoiceItemList() As Csla.SortedBindingList(Of InvoiceItem)
         Return _InvoiceItemList.GetSortedList
   End Get
End Property

Adequate method in childlist is:

<NonSerialized()> _
Private _SortedList As Csla.SortedBindingList(Of InvoiceItem) = Nothing

Public Function GetSortedList() As Csla.SortedBindingList(Of InvoiceItem)
     If _SortedList Is Nothing Then _SortedList = New Csla.SortedBindingList(Of InvoiceItem)(Me)
     Return _SortedList
End Function


Binding is implemented by VS GUI (draging form datasources).


I also have the same implementation (with private field) of exposing SBL in parentrootlist.


But in the first case databinding cancelnew method  wouldn't work and in the second case it works perfectly. What could be a reason for that?

ajj3085 replied on Wednesday, April 20, 2011

Don't expose the SBL as a property from your BO.  Instead, wrap the property in a SBL before you bind it to the BindingSource.  You'll have to write a bit of code to do this, but it should resolve your issue.

Niemand replied on Thursday, April 21, 2011

I implemented printing of BO by passing the object to the printing method. In order to support transfer of the sorting state (also filtering in some cases) of the object to the printing method the object itself should contain a reference to the actual sorted/filtered list. So wrapping the object on GUI side is not an option.

Besides I can't quite understand why can't  I do it inside a property? What's the difference when doing the same thing on GUI side or BO side?

Copyright (c) Marimer LLC