How can items in collection get collection count?

How can items in collection get collection count?

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


meierk posted on Saturday, February 09, 2008

I have a need for each item in my BusinessListBase to know how many items are in the collection, but I must be having a brain fart because the solution is eluding me.

I tried iterating through the list in my BusinessListBase and setting a count property immediately after the collection has been loaded, but that puts the collection into a Dirty state, and I don't want that behavior either.

I would greatly appreciate any help with this.

Thx,
Kevin

meierk replied on Saturday, February 09, 2008

Ok, brain started working again.  I just removed the call to PropertyHasChanged to state doesn't become dirty.  Still be interested in a better way to achieve this without having to interate over the list.


Kevin

Marjon1 replied on Saturday, February 09, 2008

Kevin,

There are three possible solutions that I can see off the top of my head:

skagen00 replied on Saturday, February 09, 2008

You can absolutely use the parent reference and cast it to the type of the collection object to get the count.

But I would be really interested in what your use case is for this, because it seems odd to me that a child would need to know the number of items in the collection.

Chris

 

meierk replied on Sunday, February 10, 2008

Thanks for the replies.

I actually did remove the call to PropertyHasChanged, however, this has a small performance hit since I am loading the collection and then reinteracting over it again. Normally a small performance hit wouldn't be an issue, but because of the design of the interface, this hit is incurred often.   In addition, this application is a rewrite of an existing Delphi application which is very fast so when the users saw the prototype they were a little disappointed.

As for the use case, I actually have two.

1)  The child collection is edited in a grid.  When the user changes the value in one of the columns, a calculated column is updated.  That calculated column has a calculation that requires total number of rows in the child collection.  The calculation is performed in the setter of the property that the user edited.

2)  I have a collection of rows where the first column is labeled "Location" with a sequential number from 0 through n.  When the data is displayed in the grid I need the first row (location 0) to read "Lead Tan" instead of "0".  I also need the last row to say "Lag Tan".  The way I approached this was to create a readonly property in my child to display the proper value, but when I originally created this property there was a rule that fixed the number of rows to 9.  Now the number of rows is variable so I
need a way of determining the max location value.

Sorry for the lengthy explainations, but I'm trying to avoid a having solutions provided without the appropriate background information.  Is there a better way to design this?  I'm sure there is, but I am plagued with learning C# and CSLA at the same time and I am restricted by the fact that I have to work with a database that I cannot change and a UI that absolutely has to match the old Delphi app.  I have some flexibility with behavior, just not the actual layout of the UI.

Thanks,
Kevin

Copyright (c) Marimer LLC