I need a sanity check...

I need a sanity check...

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

jh72i posted on Friday, October 29, 2010






I have just noticed my clsa collections no longer seem to care about the Allow flags. I set these appropriately but have just noticed that i can add to a collection that is flagged to disallow additions.

Stripping it back consider the following and tell me why the Add actually works?!?....




l = new BindingList<String>();
l.AllowNew =
l.AllowEdit =
l.AllowRemove =
string count = l.Count.ToString();


RockfordLhotka replied on Friday, October 29, 2010

Those allow flags only control interaction with data binding - they tell data binding whether the list will or won't allow the operation. They don't actually affect whether the list does or doesn't actually allow the operation via explicit code.

jh72i replied on Monday, November 01, 2010

Wow! I totally missed this somewhere along the way. You used to check for this in the BindableCollectionBase class of old. Have you intentionally removed it from the later generic versions or do I have some messed up version of the Csla code?

public abstract class BindableCollectionBase : CollectionBase, IBindingList
  object IBindingList.AddNew()
      throw new InvalidOperationException(Strings.GetResourceString("AddItemException"));
    return OnAddNew();

RockfordLhotka replied on Monday, November 01, 2010

It has been so long ago that I can't say I remember. But I suspect one of two things. Either (a) I removed the check because if Microsoft's base class didn't do it why should I? Or (b) that check was actually causing some trouble with data binding. But I'm pretty sure it was (a).

jh72i replied on Monday, November 01, 2010

Fair enough Rocky - a long time indeed in this technology. Thanks for taking the time to reply.

It's a weird one though, imho, and quite misleading of MS. I'd say there are a lot of folks out there(here!) with collections/lists/etc. that are intended to disallow adding but actually don't. I set to sorting my exposure out immediately.

Copyright (c) Marimer LLC