Select to view content in your preferred language

Select FeatureLayer graphic based on DataGrid click

746
3
01-21-2012 10:07 AM
ReneRubalcava
Esri Frequent Contributor
Please excuse my noobness when it comes to Silverlight, I'm still learning it.
I am currently trying to select an item in my FeatureLayer based on a row click of a DataGrid.
I found this thread, which I thought would get me on the right track, and I think I'm half way there.
http://forums.arcgis.com/threads/19265-Selection-Based-on-Attributes?highlight=featurelayer+selectio...

<esri:FeatureLayer ID="WorkOrders" x:Name="wo_FeatureLayer" Url="http://servername/ArcGIS/rest/services/WorkOrders/MapServer/0"
                                   OutFields="*">
</esri:FeatureLayer>


Then I have a DataGrid with some data where a single field matches an ID in my FeatureLayer. I use the DataGrids SelectionChanged event to start my query.
        private void wo_DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {

                WORK_ORDER wo = e.AddedItems[0] as WORK_ORDER;
                MessageBox.Show(wo.WorkOrderID.ToString());
                
                // when I step through on a breakpoint here, it always tells me wo_FeatureLayer is null
                var graphic = wo_FeatureLayer.Where(g => g.Attributes["MXWONUM"].ToString() == wo.WorkOrderID.ToString()).First();

                graphic.Select();
            }
            catch(Exception err)
            {
                MessageBox.Show("oops:" + err.Message);
            }
        }


The resulting error is, "Value cannot be null. Parameter name:source"
I know the FeatureLayer works, because I use it's MouseLeftDown event to populate another window without issue.

I'm sure I must be missing something simple, but a nudge in the right direction would be helpful.
Thanks.
0 Kudos
3 Replies
by Anonymous User
Not applicable
It looks like you left out the graphics property in your select statement.
Try:
var graphic = wo_FeatureLayer.Graphics.Where(g => g.Attributes["MXWONUM"].ToString() == wo.WorkOrderID.ToString()).First();
0 Kudos
ReneRubalcava
Esri Frequent Contributor
Nice catch.

It wasn't THE fix, but it got me to figure out a workaround.

I still have an issue where wo_FeatureLayer is null, but I can get around it like this.
FeatureLayer fl = Map.Layers.Where(lyr => lyr.ID == "WorkOrders").First() as FeatureLayer;


I'm still new to Silverlight, so maybe accessing MainPage.xml items is a little different.

But thanks, that helped!
0 Kudos
JenniferNery
Esri Regular Contributor
You can also do
Map.Layers["WorkOrders"] as FeatureLayer 
since Map.Layers is a LayerCollection that can be accessed by index (Layer ID).
0 Kudos