Select to view content in your preferred language

BUG? SelectionCount on FeatureLayer

2395
5
11-05-2010 11:03 AM
StevenMorlock
New Contributor II
If you select a feature on the featurelayer the PropertyChanged event is trigged with the e.PropertyName ="SelectionCount".

If you select a feature(Graphic) and then select just one other feature (Graphic) which is further down in the list of Graphics of that FeatureLayer the SelectionCount temporarily jumps to two before it jumps back to one.

So selecting first feature:
SelectionCount = 1
Selecting the second feature (discarding the first selected feature)
SelectionCount = 2
SelectionCount = 1

So the propertyChanged event is triggered twice but should only be called once. I didn't select a second feature, but just another feature.

It would also be nice if we could hoke to a SelectionChanged event. I want to prevent the user from selecting more then one feature.

hope this helps improving the API. Let me know if you need more input/clarification.
0 Kudos
5 Replies
StevenMorlock
New Contributor II
looking at reflector, you are problaby doing the following

this.raiseSelectedGraphicsChange(newGraphic, true);
this.raiseSelectedGraphicsChange(oldGraphic, false);


which throws the SelectedGraphics and SelectionCount property change to be thrown twice instead of once.

from reflector:
private void raiseSelectedGraphicsChange(Graphic g, bool isSelected)
{
    if (isSelected)
    {
        this.selectedGraphics.Add(g);
    }
    else
    {
        this.selectedGraphics.Remove(g);
    }
    base.OnPropertyChanged("SelectedGraphics");
    base.OnPropertyChanged("SelectionCount");
}
0 Kudos
JenniferNery
Esri Regular Contributor
You are right that when a selection on Graphics is made, "SelectionCount" and "SelectedGraphics" PropertyChanged are both raised. 

Can you share your code for selecting and unselecting graphic?  If you wish to maintain just a single selection at one time, I suspect that you deselect the previous graphic before you select the next graphic.  Is that right?
0 Kudos
StevenMorlock
New Contributor II
You are right that when a selection on Graphics is made, "SelectionCount" and "SelectedGraphics" PropertyChanged are both raised. 

Can you share your code for selecting and unselecting graphic?  If you wish to maintain just a single selection at one time, I suspect that you deselect the previous graphic before you select the next graphic.  Is that right?


It's not related to the fact that both SelectionCount and SelectedGraphics are being raised. It's the fact that SelectionCount (and SelectedGraphics, but not relevant for example) is raised twice when i'm only changing once.

For example, i got two roads on my FeatureLayer. I select the first one, the PropertyChanged event is raised and shows me the SelectionCount is 1, which makes sense.

Then I use the selection tool to select road 2, which will automatically deselects road 1 for you, but that will raise two PropertyChanged events!

first the SelectionCount is 2, probably because road 1 is still selected and road 2 is added.
Then the SelectionCount is 1 because road 1 is deselected.

That's why i'm thinking your code is probably doing this:

this.raiseSelectedGraphicsChange(newGraphic, true);
this.raiseSelectedGraphicsChange(oldGraphic, false);


But it shouldn't raise the SelectedGraphics Changes twice.

It should add the new graphic, remove the old graphic and THEN raise the Change event.

Hope this clarifies it a bit more.

I'm not selection features through code, but by using the editorwidget on the map with 'new' selection.
(http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Editor~Sel...)
0 Kudos
JenniferNery
Esri Regular Contributor
Oh I see, thanks for the clarification. I see what you mean now.

I looked further and I know this is by design. 

Using either EditorWidget "New Selection" button or the Editor Select command with CommandParameter="New" yields to the same result:

The first time you make a selection, "SelectionCount" and "SelectedGraphics" property changed are raised once.

The next time you make a new selection, "SelectionCount" and "SelectedGraphics" property changed are raised twice. One for deselecting previous selection and the other for making the new selection.

If now you use "Add Selection" button instead or CommandParameter="Add", the result is different in that every selection will raise "SelectionCount" and "SelectedGraphics" property changed only once each time.

This is the intended behavior.
0 Kudos
StevenMorlock
New Contributor II
thanks for your response.

i can see how this helps for databinding and so forth, but going from 1 to 2 and then back to 1 seems not correct. I would imagine it going from 1 to 0 to 1. This is also happening in certain cases. It depends on the location of the new selected feature. If it's before or after the original one. before: 1 to 0 to 1. after: 1 to 2 to 1.

anyway, thanks for you quick response!! it's appreciated. It nice to see that the actual developers take time to answer our questions!
0 Kudos