Select to view content in your preferred language

issue with migrating to v2.3 toolkit

1108
5
11-28-2011 11:02 AM
MichaelKohler
Frequent Contributor
we are in the process of upgrading to 2.3 and have a problem with the feature data grid. We have a FeatureDataGrid and when the user clicks on a record, the app zooms to and sets definition queries based on the feature. It works fine if I reference the v2.2 Toolkit.dll. As soon as I reference the v2.3 toolkit, this error pops up.

private void sectionDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sectionDataGrid.SelectedIndex > -1)
            {
                MyMap.ZoomTo(sectionDataGrid.SelectedGraphics[0].Geometry);
                string wLiner = sectionDataGrid.SelectedGraphics[0].Attributes["SECTION"].ToString();
..... other code here....                
            }


I get a null error on the ZoomTo because SelectedGraphics.Count is always 0! So I can't get to the feature to zoom or get attributes.
0 Kudos
5 Replies
OrenGal
Regular Contributor
Try to add query.ReturnGeometry = true;
I think the default is false now.
Oren.
0 Kudos
MichaelKohler
Frequent Contributor
thanks but I am not running a query. I have a FeatureDataGrid bound to data that I can't seem to get at. Whenever I click on a row in the FDG, the SelectionChanged event is fired but there are never any selected graphics

private void sectionDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sectionDataGrid.SelectedIndex > -1)
            {
                MyMap.ZoomTo(sectionDataGrid.SelectedGraphics[0].Geometry);
                string wLiner = sectionDataGrid.SelectedGraphics[0].Attributes["SECTION"].ToString();

                LayerDefinition lDef = new LayerDefinition();
                lDef.LayerID = 0;
                lDef.Definition = "CitySection = '" + wLiner + "'";

                LayerDefinition pDef = new LayerDefinition();
                pDef.LayerID = 1;
                pDef.Definition = "CITYSECT = '" + wLiner + "'";

                LayerDefinition bDef = new LayerDefinition();
                bDef.LayerID = 2;
                bDef.Definition = "SECTION = '" + wLiner + "'";


                ObservableCollection<LayerDefinition> oc = new ObservableCollection<LayerDefinition>();
                oc.Add(lDef);
                oc.Add(pDef);
                oc.Add(bDef);

                ArcGISDynamicMapServiceLayer l = MyMap.Layers["Liner"] as ArcGISDynamicMapServiceLayer;
                l.LayerDefinitions = oc;

                l.Refresh();
                if (l.Visible == false) l.Visible = true;
                
            }


<esri:FeatureDataGrid x:Name="sectionDataGrid" 
                                  Grid.Row="0" FontSize="8" 
                                  Map="{Binding ElementName=MyMap}" 
                                  GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[Sections]}" 
                                  SelectionChanged="sectionDataGrid_SelectionChanged"/>
0 Kudos
MichaelKohler
Frequent Contributor
No luck getting at the data the way I used to with v2.2. Had to work around by getting the value out of the selected row for a specified column. Then do a query to get to the geomerty so I could zoom to the feature. And finally, set the definition queries to show only the needed data. Still hoping for some clarification here.

private void sectionDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (sectionDataGrid.SelectedIndex > -1)
            {
                DataGridColumn d = sectionDataGrid.Columns[0];
                FrameworkElement fe = d.GetCellContent(sectionDataGrid.SelectedItem);
                TextBlock tb = fe as TextBlock;
                string wLiner = tb.Text.ToString();

                QueryTask qt = new QueryTask("http://pslgis.cityofpsl.com/ArcGIS/rest/services/LinerProjectSections/MapServer/0");
                Query q = new Query();
                q.Where = "SECTION = '" + wLiner + "'";
                q.ReturnGeometry = true;
                q.OutSpatialReference = MyMap.SpatialReference;
                qt.ExecuteCompleted += qt_ExecuteCompleted;
                qt.ExecuteAsync(q);

                LayerDefinition lDef = new LayerDefinition();
                lDef.LayerID = 0;
                lDef.Definition = "CitySection = '" + wLiner + "'";

                LayerDefinition pDef = new LayerDefinition();
                pDef.LayerID = 1;
                pDef.Definition = "CITYSECT = '" + wLiner + "'";

                LayerDefinition bDef = new LayerDefinition();
                bDef.LayerID = 2;
                bDef.Definition = "SECTION = '" + wLiner + "'";

                ObservableCollection<LayerDefinition> oc = new ObservableCollection<LayerDefinition>();
                oc.Add(lDef);
                oc.Add(pDef);
                oc.Add(bDef);

                ArcGISDynamicMapServiceLayer l = MyMap.Layers["Liner"] as ArcGISDynamicMapServiceLayer;
                l.LayerDefinitions = oc;

                l.Refresh();
                if (l.Visible == false) l.Visible = true;
                
            }
        }

        private void qt_ExecuteCompleted(object sender, QueryEventArgs e)
        {
            MyMap.ZoomTo(e.FeatureSet.Features[0].Geometry);
        }
0 Kudos
MarkusHjärne
Deactivated User
Hi,

I hade the same experience when upgrading from v2.1 to v.2.4.

You can find the workaround I used here: http://forums.arcgis.com/threads/26383-Problem-to-zoom-to-selected-graphic-for-the-feature-datagrid

Hope this can be of any help.

/Markus
0 Kudos
JenniferNery
Esri Regular Contributor
I apologize for the inconvenience. FeatureDataGrid.SelectedGraphics is always equal to the GraphicsLayer.SelectedGraphics in v2.3 and up. You might want to use e.AddedItems as suggested in post# 2 of this thread: http://forums.arcgis.com/threads/46013-FeatureDataGrid-Selection-Changed-Event
0 Kudos