CSLA .NET

From Rockford Lhotka's Expert C# 2008 and VB 2008 Business Objects books

Fixed size editable list

rated by 0 users
This post has 0 Replies | 0 Followers

Top 75 Contributor
Points 1,550
boo Posted: Wed, Oct 31 2007 9:30 PM
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.
  • | Post Points: 5
Page 1 of 1 (1 items) | RSS

Please contact Magenic for your .NET consulting
and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems