Datagridview binding issues with BusinessListBase Child (Windows forms)

Datagridview binding issues with BusinessListBase Child (Windows forms)

Old forum URL:

gajit posted on Friday, March 09, 2012

Hi all,

I wonder if anyone can help.

I'm having some issues with my databinding on a child collection - businesslistbase.

The form is a userprofile->userroles entry, that mimics closely say the project-> projectresources relationship in the project tracker project.

The business objects fetches correctly, and the datagridview contains roles currently assigned to a user.

If I then add a role, using this code:

         If cboRoles.Text <> "" Then


            Catch ex As InvalidOperationException
                MessageBox.Show(ex.ToString, _
                  "Error assigning", MessageBoxButtons.OK, _

            Catch ex As Exception
                MessageBox.Show(ex.ToString, _
                  "Error assigning", MessageBoxButtons.OK, _
            End Try

        End If

The role is indeed added to the collection, and I am able to save the object. What doesn't happen before I apply the save, is the role does not appear in my datagridview - unless I change a value on the parent object.

But that's not the most critical problem...

When I remove a role from the collection, by executing this code:

        If Me.ROLESDataGridView.SelectedRows.Count > 0 Then

            Dim row As Integer = ROLESDataGridView.CurrentCell.RowIndex
            Dim role As String = ROLESDataGridView.Item(0, row).Value


        End If

I believe the role gets removed, but then I get an exception:

"DataGridView Default Exception"

System.IndexOutOfRangeException: Index n does not have a value. at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)

Clearly the binding isn't working correctly.

I have checked the properties of my datagridview against those in the ProjectTracker sample solution (and also against what I had in my CSLA2 version of this project) and everything seems correct. I also checked the binding sources in the project and they seem fine also.

Any ideas on what the problem could be?






gajit replied on Friday, March 09, 2012

This resolves the problem(s):






I can live with this, but I'm curious as to why we now need to rebind manually instead of it automatically rebinding? Is this a result of a .Net change or a CSLA change?

The windows forms projecttracker solution doesn't reset the binding. but I suspect that project doesn't actually run...

Any insight would be helpful.



JonnyBee replied on Friday, March 09, 2012

Only BusinessBindingListBase, DynamicBindingListBase and ReadOnlyBindingListBase works properly with Windows Forms. 

BusinessListBase and ReadOnlyListBase classes inherit from ObservableCollection and they do NOT work properly with Windows Forms databinding - these classes are for  WPF/SL/WP and Web.

This is described in Using Csla 4 - Creating Business Objects - Chapter 3 - Windows Forms Types.

gajit replied on Friday, March 09, 2012

Excellent - that did the trick - I wa able to remove the ResetBinding call and binding worked as expected.

So when was the distinction made between BLB and BBLB? Obviously after CSLA2.1. Just curious...

Thanks again,




JonnyBee replied on Friday, March 09, 2012

Changed in 4.0. 

Copyright (c) Marimer LLC