Select to view content in your preferred language

Interactive data table for GraphicsLayers

1689
13
Jump to solution
01-30-2012 01:15 PM
JianChen
Regular Contributor
The ESRI sample (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid) shows a way to create an interactive data table for GraphicLayer (click the map, associated feature will highlight in the FeatureDataGrid, Vice versa). The core part is the FeatureLayer_MouseLeftDown function as below:

private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)         {             args.Graphic.Selected = !args.Graphic.Selected;             if (args.Graphic.Selected)                 MyDataGrid.ScrollIntoView(args.Graphic, null);         }


XAML code from Sample:

<esri:FeatureLayer ID="California" Renderer="{StaticResource SelectRenderer}"      Url="http://serverapps.esri.com/ArcGIS/rest/services/California/MapServer/8"      OutFields="*" MouseLeftButtonDown="FeatureLayer_MouseLeftButtonDown" /> ... <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"     Map="{Binding ElementName=MyMap}"     GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[California]}" />
  The map user click actually is a feature layer and the featureDataGrid is binding to a GraphicsLayer (the same feature layer anyway). I make some changes from the sample for my application. If I get rid of the feature layer and the GraphicsLayer is returned from a query and I worte a similar GraphicsLayer_MouseLeftButton Down function, if you click the map, the entry in the FeatureDataGrid can be highlighted, but when I click a row in the FeatureDataGrid, the feature on the map doesn't highlight. What do I miss here?  
 private void GraphicsLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs e)         {             e.Graphic.Selected = !e.Graphic.Selected;             if (e.Graphic.Selected)                 MyDataGrid.ScrollIntoView(e.Graphic, null);         }


The XAML from my code:

<esri:GraphicsLayer ID="MyGraphicsLayer" MouseLeftButtonDown="GraphicsLayer_MouseLeftButtonDown" /> .... <esri:FeatureDataGrid x:Name="MyDataGrid" Background="White"     Map="{Binding ElementName=MyMap}"     GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[MyGraphicsLayer]}" >                           </esri:FeatureDataGrid>
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
I think I got your issue.

It's not tied to your feature datagrid. Your selection by mouse click is not working either.

I think it's related to your symbol that is not managing the 'Selected' state. So your feature is selected but there is no visual effect.

You can either create your own custom symbol or use the feature service symbol.

In your XAML, add this line: xmlns:symbols="clr-namespace:ESRI.ArcGIS.Client.FeatureService.Symbols;assembly=ESRI.ArcGIS.Client"

and define your fill symbol this way:

<symbols:SimpleFillSymbol x:Key="DefaultFillSymbol" SelectionColor="Cyan" />

That should do the trick.



View solution in original post

0 Kudos
13 Replies
DominiqueBroux
Esri Frequent Contributor
if you click the map, the entry in the FeatureDataGrid can be highlighted, but when I click a row in the FeatureDataGrid, the feature on the map doesn't highlight. What do I miss here?

Most generally this means that the Map of the FeatureDataGrid is not or badly initialized.

If this is the only location you initialize the Map
Map="{Binding ElementName=MyMap}"

my best bet would be that the Map is not called 'MyMap'.
Check that point. I have no others ideas anyway.
0 Kudos
JianChen
Regular Contributor
Most generally this means that the Map of the FeatureDataGrid is not or badly initialized.

If this is the only location you initialize the Map
Map="{Binding ElementName=MyMap}"

my best bet would be that the Map is not called 'MyMap'.
Check that point. I have no others ideas anyway.


Thanks Dominique! I double checked and that is the only place I initialize the map and there's no other Map object in this project. So I don't have any idea but I'll keep digging it.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Did you check taht your map is called 'MyMap' ?
0 Kudos
KenCarrier
Deactivated User
Did you check taht your map is called 'MyMap' ?


Is there any way to use a FeatureDataGrid without a map.

If I just wanting to edit a standalone table published as a FeatureServer service could I read the rows directly into the FeatureDataGrid?
0 Kudos
JianChen
Regular Contributor
Did you check taht your map is called 'MyMap' ?
Positive! My map is called "MyMap" and I only initialize the FeatureDataGrid once in the XAML. I don't have any clue about what's wrong.
0 Kudos
JianChen
Regular Contributor
I'm also thinking about write a function to response the LeftMouseDown event on FeatureDataGrid. But I don't know how to connect FeatureDataGrid back to GraphicsLayer. As we understand, a MouseLeftButtonDown function can use a selected graphic as an input of datagrid's ScrollIntoView function to find associated record. In a similar function on FeatureDataGrid, I can think about using selectedItem as a bridge to get the associated graphic in the GraphicsLayer. But how to do that? The next question is how to highlight the target feature in GraphicsLayer�? I couldn't find a method of GraphicsLayer can allow me to do this. Any idea? Thanks!
0 Kudos
JenniferNery
Esri Regular Contributor
You can look at this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid
Code-behind (this can also be on GraphicsLayer_MouseLeftButtonDown):
        private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
        {
            args.Graphic.Selected = !args.Graphic.Selected;
            if (args.Graphic.Selected)
                MyDataGrid.ScrollIntoView(args.Graphic, null);
        }


FeatureDataGrid.GraphicsLayer can be bound to a GraphicsLayer. It's fields will come from GraphicsLayer.Graphics.Attributes.
0 Kudos
JianChen
Regular Contributor
You can look at this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#FeatureDataGrid
Code-behind (this can also be on GraphicsLayer_MouseLeftButtonDown):
        private void FeatureLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
        {
            args.Graphic.Selected = !args.Graphic.Selected;
            if (args.Graphic.Selected)
                MyDataGrid.ScrollIntoView(args.Graphic, null);
        }


FeatureDataGrid.GraphicsLayer can be bound to a GraphicsLayer. It's fields will come from GraphicsLayer.Graphics.Attributes.


I already did what you suggested (as code included in the initial post). But somehow it doesn't work. I'm struggling in troubleshooting these days.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
No idea.
Can you share a piece of code allowing to reproduce the issue?
0 Kudos