Select to view content in your preferred language

Prevent FeatureDataGrid from selecting the first row after panning the map

827
1
01-17-2011 03:23 AM
MarkJagt
New Contributor
Does anyone know how I can prevent the first row in the FeatureDataGrid from being selected after a panning action has been performed on the Map?

When my application starts, nothing is selected in the FeatureDataGrid. But as soon as I pan the map, the first row in the FeatureDataGrid is selected. I can repeat this behavior in the sample found here: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#ToolkitFeatureDataGrid.

In the sample this behavior happens only once, but in my application it continues selecting the first row after panning, even if I clear the selection in between the panning actions. The 'first row selection' does not happen when I zoom in or out on the map.

Any ideas?

Regards,
Mark
0 Kudos
1 Reply
AliMirzabeigi
Emerging Contributor
Mark,

Thank you for your posting. We are currently looking into this problem. In the meantime you can have a variable to keep track of the selection count whenever there is a change in your feature layer graphics collection AND the selection in your layer.

You should clear the selection when:
1. There was no selection in your layer previously, AND
2. Current selection count is equal to 1

Your code whould be something similar to the following code snippet:

int selectedCount; // Variable to keep track of the selection count in FeatureLayer

public YourUserControlClassConstructor()
{
  InitializeComponent();
  
  FeatureLayer featureLayer = MyMap.Layers["MyFeatureLayer"] asFeatureLayer;
  featureLayer.Graphics.CollectionChanged += Graphics_CollectionChanged;
  selectedCount = featureLayer.SelectionCount;
}
 
privatevoid Graphics_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
  if (selectedCount == 0 /* No selections before */
      && MyDataGrid.SelectedItems.Count == 1 /* Unwanted selection after the change in graphics collection */)
  MyDataGrid.SelectedItems.Clear();
  selectedCount = MyDataGrid.SelectedItems.Count;
}


Hope this helps.
0 Kudos