CSLA.NET 3.5: how to track the deleted item in ListChangedEvent?CSLA.NET 3.5: how to track the deleted item in ListChangedEvent?
Old forum URL: forums.lhotka.net/forums/t/5477.aspx
Patrick posted on Friday, September 26, 2008
Hi,
for a WinForms data binding scenario I need to track which items are delete from a BusinessListBase.
The problem is, that by the time the ListChangedEvent fires the item is not in the list anymore and the NewIndex which is passed through the ListChangedEvent is out of bound for the original list (as the item is already moved to the deletedList).
It's also not possible to look at the latest item in the deletedItems list as this is internal to BusinessListBase.
Any suggestions on how to do this please?
Thanks a lot,
Patrick
PS: Here is the code from BusinessListBase for reference:
protected override void RemoveItem(int index)
{
// when an object is 'removed' it is really
// being deleted, so do the deletion work
C child = this[index];
bool oldRaiseListChangedEvents = this.RaiseListChangedEvents;
try
{
this.RaiseListChangedEvents = false;
RemoveIndexItem(child);
RemoveFromMap(child);
base.RemoveItem(index);
}
finally
{
this.RaiseListChangedEvents = oldRaiseListChangedEvents;
}
if (!_completelyRemoveChild)
{
// the child shouldn't be completely removed,
// so copy it to the deleted list
CopyToDeletedList(child);
}
if (RaiseListChangedEvents)
OnListChanged(new ListChangedEventArgs(ListChangedType.ItemDeleted, index));
}sergeyb replied on Friday, September 26, 2008
Perhaps you could expose DeletedList to UI? Why do you
need to keep track of those, BTW?
Sergey Barskiy
Principal Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: Patrick
[mailto:cslanet@lhotka.net]
Sent: Friday, September 26, 2008 6:06 PM
To: Sergey Barskiy
Subject: [CSLA .NET] CSLA.NET 3.5: how to track the deleted item in
ListChangedEvent?
Hi,
for a WinForms data binding scenario I need to track which items are delete
from a BusinessListBase.
The problem is, that by the time the ListChangedEvent fires the item is not in
the list anymore and the NewIndex which is passed through the ListChangedEvent
is out of bound for the original list (as the item is already moved to the
deletedList).
It's also not possible to look at the latest item in the deletedItems list as
this is internal to BusinessListBase.
Any suggestions on how to do this please?
Thanks a lot,
Patrick
PS: Here is the code from BusinessListBase for reference:
protected override void RemoveItem(int index)
{
// when an object is 'removed' it is really
// being deleted, so do the deletion work
C child = this[index];
bool oldRaiseListChangedEvents =
this.RaiseListChangedEvents;
try
{
this.RaiseListChangedEvents = false;
RemoveIndexItem(child);
RemoveFromMap(child);
base.RemoveItem(index);
}
finally
{
this.RaiseListChangedEvents =
oldRaiseListChangedEvents;
}
if (!_completelyRemoveChild)
{
// the child shouldn't be completely
removed,
// so copy it to the deleted list
CopyToDeletedList(child);
}
if (RaiseListChangedEvents)
OnListChanged(new
ListChangedEventArgs(ListChangedType.ItemDeleted, index));
}
Patrick replied on Sunday, September 28, 2008
sergeyb: Perhaps you could expose DeletedList to UI? Why do you
need to keep track of those, BTW?
I have a UI control which displays the business objects (as a node graph) using custom data binding. So I need to know which node was removed to remove it from the graph.
Exposing DeletedList wouldn't help that much as I don't know the index of the deleted item in the list... I could assume it's always the last one but that might not always work.
Thanks,
Patrick
rasupit replied on Sunday, September 28, 2008
How about overriding RemoveItem and add ListChangingEvent
Patrick replied on Sunday, September 28, 2008
rasupit: How about overriding RemoveItem and add ListChangingEvent
Sound like a good idea thanks... I'm really surprised though that this hasn't been a problem for more people...
I would be interested to know how e.g. a bound grid control handles this as it correctly removes the item from the list and it also wouldn't be able to obtain a reference of the deleted item (so either it compares it's internal list against the bound list or it does a reset internally)?
Thanks,
Patrick
rasupit replied on Sunday, September 28, 2008
Patrick: I'm really surprised though that this hasn't been a problem for more people...
I think because people just interested in ListChangedType.ItemDeleted and not the index. You could also argue why is it being passed if it not useful. I think the index is being passed just to fulfill the ListChangedEventArgs signature.
RockfordLhotka replied on Sunday, September 28, 2008
This was a problem for more people. Which is why CSLA collections have the RemovingItem event (from ExtendedBindingList), and it provides access to the item that's being removed.Patrick replied on Thursday, October 23, 2008
Thank you Rocky
Copyright (c) Marimer LLC