I've got a windows form which binds a bunch of Checkboxes to a Data Transfer Object (DTO). These DTO's are gotten from a corresponding Listview of Users.
The problem I'm running into is that if the ListView contains more than 2 users. For example, I select User1, the checkboxes are properly bound/displayed with their values. Select a blank space, the checkboxes are disabled (as they should be). Select User1 again, and this time the checkboxes are not bound. Why?
Illustrated:
Click on vmware, permissions are populated

Click on a blank space in the User list, permissions are disabled.

Click on vmware again, permissions are blank. I've checked the underlaying DTO which is getting bound, and it contains the correct data.

The code for the SelectedIndexChanged on the User listview:
Code Snippet
private void lvUsersGroups_SelectedIndexChanged( object sender, EventArgs e )
{
//todo: fix double selection bug (select user, select blank space, select same user again)
if ( accountPermissionsBS.Count > 0 )
accountPermissionsBS.EndEdit();
if ( lvUsersGroups.SelectedIndices.Count > 0 )
{
btnRemove.Enabled = true;
EnablePermissions(); //Enables editing of Checkboxes
AccountSecurity s = GetAccountSecurityBySid( lvUsersGroups.SelectedItems[ 0 ].Tag as User );
if ( accountPermissionsBS.Count > 0 )
accountPermissionsBS.RemoveCurrent();
accountPermissionsBS.DataSource = s.Permissions;
}
else
{
btnRemove.Enabled = false;
DisablePermissions(); //Disables editing of Checkboxes
}
}
I've already played around with accountPermissionsBS.ResetBindings() (and other Reset settings), yet it doesn't help.
How do I make the checkboxes properly re-bind to the datasource?