ListModel but for a Dictionary?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

ListModel but for a Dictionary?

Christopher J. Demers
Is there anything that works like a ListModel (adding support for change
events) but for a Dictionary?

Chris


Reply | Threaded
Open this post in threaded view
|

Re: ListModel but for a Dictionary?

Ted Bracht-2
Hi Chris,

"Christopher J. Demers" <[hidden email]> wrote in message news:<9eckul$290tu$[hidden email]>...
> Is there anything that works like a ListModel (adding support for change
> events) but for a Dictionary?
>
> Chris

Have you tried to put associations (key-value pairs) in a ListModel?
That basically gives you the same as a Directory

HTH

Ted


Reply | Threaded
Open this post in threaded view
|

Re: ListModel but for a Dictionary?

Christopher J. Demers
Ted Bracht <[hidden email]> wrote in message
news:[hidden email]...
> Have you tried to put associations (key-value pairs) in a ListModel?
> That basically gives you the same as a Directory

I did something like that, but it seems that it would be nicer if there were
something similar to ListModel but with better Dictionary support.  Perhaps
I will make one, if I have a free moment.

I need a dictionary for efficient lookups.  I also need to display it in a
list box.  I just get the associations from the Dictionary and wrap that in
a ListModel.  When the Dictionary changes however I have to regenerate the
contents of the ListModel.

Thanks,

Chris


Reply | Threaded
Open this post in threaded view
|

Re: ListModel but for a Dictionary?

Frank A. Adrian
"Christopher J. Demers" <[hidden email]> wrote in
message news:9eemin$2bs2l$[hidden email]...
> I need a dictionary for efficient lookups.  I also need to display it in a
> list box.  I just get the associations from the Dictionary and wrap that
in
> a ListModel.  When the Dictionary changes however I have to regenerate the
> contents of the ListModel.

My questions would be:

(a) Is it incredibly slow to regenerate the ListModel after modifying the
Dictionary contents?
(b) Is it amazingly clunky to update the ListModel after the Dictionary
changes?

If neither of these are true, I'd just go with the XP dictum to "Do the
simplest thing that could possibly work" and keep the code the same.  I
can't believe that you'd have that many items in your Dictionary anyway
because, if you did, you'd have too many to effectively have the user do
anything with them via a ListBox.  In fact, given what you've described, I'd
question the need to use a Dictionary rather than a simple OrderedCollection
as the target for the ListModel.  You have done this because you've profiled
the code, haven't you?  If not, you're probably over-engineering this
portion of your system.

faa


Reply | Threaded
Open this post in threaded view
|

Re: ListModel but for a Dictionary?

Christopher J. Demers
Frank A. Adrian <[hidden email]> wrote in message
news:tk%P6.2607$[hidden email]...
>
> (a) Is it incredibly slow to regenerate the ListModel after modifying the
> Dictionary contents?

No, it is not slow.

> (b) Is it amazingly clunky to update the ListModel after the Dictionary
> changes?

I guess it is not _that_ clunky to update the ListModel.

> If neither of these are true, I'd just go with the XP dictum to "Do the
> simplest thing that could possibly work" and keep the code the same.  I
> can't believe that you'd have that many items in your Dictionary anyway
> because, if you did, you'd have too many to effectively have the user do
> anything with them via a ListBox.  In fact, given what you've described,
I'd
> question the need to use a Dictionary rather than a simple
OrderedCollection
> as the target for the ListModel.  You have done this because you've
profiled
> the code, haven't you?  If not, you're probably over-engineering this
> portion of your system.

I probably did not state my point well when I said "I need a dictionary for
efficient lookups", I think I should have said "I want to use a dictionary
because I am doing lookups". ;)  I am developing a rapid prototype for
in-house experimentation.  I am trying to code very quickly just to try out
some experimental concepts.  When I need to do lookups I naturally turn to a
Dictionary or LookupTable.  I do this for efficiency in two respects, lookup
speed (which may not always be important), and I like to use existing code
(if it fits) rather than write my own if I can (I consider this more
important).  I understand that I could store my objects in an
OrderedCollection and do the look up with detect, etc...  However that is
more code I have to maintain (which adds some complexity, even if only a
small amount) then if I just use the functionality built into Dictionary.
For me it seems simpler to use the Dictionary where appropriate.

The only reason I would consider using something other than a Dictionary her
e would be the UI interfacing.  I don't want UI considerations to impact my
domain model too much.  Some impact is unavoidable, but I prefer to keep
them separate as much as I can.  I really like the ListModel concept because
it almost seamlessly adapts a Collection to improve UI interfacing.

I have needed to display Dictionaries in list boxes in a number of different
applications.  Each time I have to do special coding to get the associations
and throw them in a ListModel.  It just seems like a DictionaryModel might
be of use as a general purpose plugable adapter.  In saying that I also need
to mention that it has not been important enough to me to actually write one
(yet), so I don't feel that strongly about it (yet).  Right now I am just
thinking about it. ;)

Chris