Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Item Adding functionality (Read 1979 times)
hrumayor
YaBB Newbies
*
Offline



Posts: 24
Location: Canada
Joined: Jun 3rd, 2009
Item Adding functionality
Jun 3rd, 2009 at 2:27pm
Print Post  
Hi,

I would like to have a ItemAdding so I can do some operations on it before it is added to the items collection is there a way to do this?
At this point I am using ItemAdded, what I want to do is generate a unique identifier and to do that I want to make some enforcements because the item gets added before I can do this check I have to filter it first it would be nice if I got a pre addition event to handle this type of functionally.

Hugo
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Item Adding functionality
Reply #1 - Jun 3rd, 2009 at 2:42pm
Print Post  
Hi,

Do you want it to be a validation event that can be cancelled?

Stoyan
  
Back to top
 
IP Logged
 
hrumayor
YaBB Newbies
*
Offline



Posts: 24
Location: Canada
Joined: Jun 3rd, 2009
Re: Item Adding functionality
Reply #2 - Jun 3rd, 2009 at 6:02pm
Print Post  
Yes that would be OK, it is more like adding the final construction step depending on what is already on the items. but a validation event would be good, it you don't need the cancellation simply you don't set it. I am emulating the event by ignoring the node that got inserted.

eg.

void OnItemAdded(object sender, ItemEventArgs e)
{
if (e.Item is WidgetBase)
{
var widget = (WidgetBase)e.Item;
var widgets = Nodes.Cast<WidgetBase>()
.Where(w => w != widget);

if (widget.Id < 0)
widget.Id = widgets.FirstOrDefault() == null ? 0 : widgets.Max(s => s.Id) + 1;
}
}
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Item Adding functionality
Reply #3 - Jun 3rd, 2009 at 6:29pm
Print Post  
It seems the collection classes raise some internal events when adding items in order to synchronize with other collections (e.g. diag.Items.Add also adds to diag.Nodes), and this happens before the item is actually added. We'll consider making them public, or otherwise add a new event for this purpose.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint