Fixed size editable list

Fixed size editable list

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


boo posted on Wednesday, October 31, 2007

I've recently come across this a couple of times:

The use case is that you have a list of items that is configurable by administrator, say a question answer list where the admin enters questions and the user enters answers.

One way to solve this is the traditional, open a single question as an editable item, then provide an answer.  However when the user has 50 items, this isn't friendly, especially if the answers are yes/no or simple one or two letter word answers.  Sometimes you just want to see the whole list and provide answers to each question.  A dictionary won't work because you can't detect when items are added or deleted or changed.

So the problem is that you want a list where you can edit the items themselves (or at least one of the properties, some may be read-only), but you don't want to allow developers to add or remove items from the list of items itself.

The answer I came up with was simply to use the normal editable list (because the child objects are editable and you need to detect changes, it can't be a read only list), but I added a field so that the business object couldn't have items deleted or added (except when done internally as part of a Fetch method).  To do this I added a boolean _isFixed field that is initially set to true and I overrode the AddNewCore and RemoveItem to throw a not supported exception if the _isFixed is currently set to true.  When I'm in the Fetch method adding objects to the list I simply change the _isFixed to false at the begining of the method and back to true at the end; similiar to the call to RaiseListChangedEvents and such.

I'd like to see in 3.1 or 3.5 a new business object and template that is basically a formal implementation of this.  Basically it's the editable list with this extra field and shouldn't be a big deal to implement.

Hope this sounds as good of an idea to everyone else as it does me.

Copyright (c) Marimer LLC