How to update ReadOnlyListBase

How to update ReadOnlyListBase

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


RaulLozano posted on Tuesday, March 22, 2011

I have a ReadOnlyListBase that is bound to a grid that is used to display a list of raw-material objects. The grid only shows about 5% of the properties contained on the full raw-material object.

The idea is that when the user double clicks a row on the grid the application retrieves the full raw-material object (BussinesBase) and displays it on its own form so that the user can edit it.

All this is great but the problem is what to do with the ReadOnlyListBase item once it has been updated (after the user double-clicked the grid and updated the raw-material on the external form). I hate to have to fetch the whole ReadOnlyListBase again just to show the updated data for only one of the items.

Am I approaching this the wrong way? How do you guys handle this type of scenario?

Thanks.

JonnyBee replied on Wednesday, March 23, 2011

Is your app a single user application?

If not - then how would you make sure to update the list with changes from other users?

Sometimes - I find we try to make things more complicated/optimized than they may need to be.
I'd probably just refetch the entire list to keep it updated.

RockfordLhotka replied on Wednesday, March 23, 2011

I am with Jonny - by default I'll just refresh the list.

If that is a performance problem, then you can look at more complex alternatives.

One relatively easy alternative:

  1. Enhance the read-only child class contained in the list to add support for direct fetching (add a static factory and DataPortal_Fetch)
  2. Add a RefreshItem method to the collection, and in this method:
    1. Reload the changed read-only child
    2. Mark the list as IsReadOnly false
    3. Replace the old item with the new one
    4. Mark the list as IsReadOnly true

 

RaulLozano replied on Wednesday, March 23, 2011

Thanks guys.

I think I am going to go for the refresh method as follows:

I will add a Refresh method on the child object that takes a full RawMaterial object as its argument. Inside this Refresh method I will simply copy the new values from the full RawMaterial object to the child object.

Of course, I am not sure if the read-only child (ReadOnlyBase) implements all the pluming necessary to fire the property change events so the grid is able to reflect the new values. I will need to verify this when I am back at my development computer.

This is more than a performance issue by the way. This is a multiuser application and I don’t want to refresh the whole list and have users see changes to items they didn’t initiate changes on, this may freak users out and think there is a bug with the application. I also think (I am not sure) that when I rebind the list to the grid I am going to have to add a bunch of extra code to scroll the grid to its last scroll state, set the grid selected item etc, etc.

So, is the Refresh item idea asking for trouble?

Thanks.

tmg4340 replied on Wednesday, March 23, 2011

RaulLozano


This is more than a performance issue by the way. This is a multiuser application and I don’t want to refresh the whole list and have users see changes to items they didn’t initiate changes on, this may freak users out and think there is a bug with the application.

Yes - but consider this.  Won't your users "freak out" if they choose to edit an item from your list and see your edit screen showing different data than what's in the list?  They are going to see the change somewhere.  In a multi-user app, it's not an uncommon occurrence to see data "move" on you.

I'm not saying that going the "refresh item" idea is bad.  I just think you may be choosing the more-complicated implementation to avoid a problem that you're going to run into eventually anyway.

HTH

- Scott

RaulLozano replied on Wednesday, March 23, 2011

tmg4340

Yes - but consider this.  Won't your users "freak out" if they choose to edit an item from your list and see your edit screen showing different data than what's in the list?  They are going to see the change somewhere.  In a multi-user app, it's not an uncommon occurrence to see data "move" on you.

ah yes, that is true and I had tough of that too. I have the time stamp value of the raw-material object on the list and I was going to compare that value against the time stamp value of the full raw-material object and if they are different then I was going to popup a message box letting the user know about the issue. And yes, I realize that I can do the same thing if I refreshed the list in case the list had changed but that looks like a far more complex solution.

I am starting to get the feeling that I may be swimming against the current with this one. I was sure that my approach would have been the best way to go but it looks like it may just be me thinking that.

tetranz replied on Wednesday, March 23, 2011

Long ago I implement an observer pattern mechanism for handling this and have been using it ever since. It's quite simple and it works very well. My ReadOnly collections register with the "Observer" by supplying a delegate and indicating what type of object it wants to be told about. My BusinessBase and other objects call the Observer in their Save method. The readonly collection is told the id of the object affected and whether it was added, updated or deleted.  The collection then fires a ListChanged event so the UI is updated. I have some code in the UI to select and highlight the correct grid row. It's not just useful for grids but dropdown combo boxes etc.

Some of my queries are quite heavy and I wouldn't want to do it on every update.

Unfortunately I've never really documented and made it general enough to publish. The observer is basically a Dictionary / HashTable keyed on full type names. Value is a collection of delegates. It's important to unregister when a collection is destroyed so we're not trying to call delegates on dead objects and cause memory leaks.

Yes the multi-user issue exists as others have described. It's not really an issue in my applications since whoever creates a record normally "owns" it so records are not normally changed by someone else.

onlyash replied on Wednesday, August 31, 2011

Hi...can u post the code for the same. I am new to CSLA and want to add selected item(s) from gridview to a listbox .

Copyright (c) Marimer LLC