Being notified when a selection was just made

556
3
11-08-2011 05:06 AM
Labels (1)
AndreMachado
New Contributor
Hello,

I've a property grid that I want to show the common attributes for the selected elements in the map. I've seen two different ways to do it:

1) Attaching a method to the OnEditCompleted() event in the ESRI.ArcGIS.Client.Editor class. So I can check that the user just finish selecting the elements and I can take the SelectedGraphics collection.

2) Using the SelectedGraphics property in the GraphicsLayer class. In fact, I can't use directly. You have exposed the property as a IEnumerable<Graphic> altough the private field that is returned is an ObservableCollection<Graphic> (why not exposing it directly as a observable collection?). So I cast this property to it's original value and attach a method to the CollectionChanged event. This allows me to know when an element has been selected (or deselected).

Ok, but each method has its share of problems:

#1) That works ok. But what if I can select from other places, like from a tree view with all elements? This tree view, for example, has nothing to do with the Editor (directly). I'll change the Selected property for the element (graphic) but this event wont be fired (expected).

#2) If I select 100 elements, the CollectionChanged event will be fired 100 times. No matter what I do, it becames slow.

So, what I need is a generic way (event?) to know when the user has just finish selecting elements. Be it 100 elements or just one, I would attach a method to an event and be notified just one time.

Am I missing something? Do we have some way to do it today?

Thank you!

André
0 Kudos
3 Replies
JenniferNery
Esri Regular Contributor
You can subscribe to GraphicsLayer.PropertyChanged event and check for e.PropertyName = "SelectionCount" or "SelectedGraphics". Both of these properties will raise PropertyChanged event when graphics are added to or removed from SelectedGraphics. You can check for graphic.Selected property.
0 Kudos
AndreMachado
New Contributor
You can subscribe to GraphicsLayer.PropertyChanged event and check for e.PropertyName = "SelectionCount" or "SelectedGraphics". Both of these properties will raise PropertyChanged event when graphics are added to or removed from SelectedGraphics. You can check for graphic.Selected property.


Thank you Jennifer. But the problem is: if I support multiple selection and the user selects 100 elements, this event will be fired 100 times, right? That will be not good from a performance perspective because I'll need to also treat this event 100 times...

Thanks!

Andre
0 Kudos
JenniferNery
Esri Regular Contributor
I think the best approach then would be #1 in your first post: Use Editor.EditCompleted event. And should selection come from TreeView, you could add your own event that returns you selected graphics.
0 Kudos