Select to view content in your preferred language

FeatureDataGrid_SelectionChanged event

3950
6
08-08-2012 08:56 AM
DavidAshton
Frequent Contributor
I just upgaded an application from 2.1 API to 3.0 API to take advantage of some new functionality.  Currently I haven't changed any code other than swapping out the new assemblies.

Here's my issue:

With 2.1 The FeatureDataGrid_SelectionChanged Event doesn't fire until I select a record in the feature data grid, so it doesn't fire upon the selection of the graphics but in 3.0 the event fires right after a selection (spatial or attribute) selection is made (when the feature data grid is first populated).
 
private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
}


How do I get the code not to fire when the feature data grid is first populated?

Dave
0 Kudos
6 Replies
JenniferNery
Esri Regular Contributor
This is the intended design for FeatureDataGrid, that it would share the SelectedGraphics with its associated GraphicsLayer, which means, selected graphic means selected row, thus you see SelectionChanged event firing. If you need this changed, you can download source code: http://esrisilverlight.codeplex.com/, you can ignore calls to RestorePreviousSelection() method, this method is being used to synchronize the layer and the datagrid.
0 Kudos
DavidAshton
Frequent Contributor
Jennifer,

Thanks for the reply. I'm not sure if I need or can change the source code.  After further investigation here's what I have discovered:

Here's my code:

 private void FeatureDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
  
            var graphics = (sender as ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid).SelectedGraphics;
            foreach (var g in graphics)
            {
                // get id 
                var id = g.Attributes["APN"];

                string apn10 = (string)id;

                IDValue.Text = apn10;
                

                // TODO: retrieve outside data for this id
                //    PARCELIDPASS.Text = string.Format("The ParcelID passed is {0}", id);
                PARCELIDPASS.Text = apn10;
                break;
                
            }



As I stated in my 2.1 application everything works fine.  I make a spatial selection and my featuredatagrid gets populated and the code doesn't fire.  When I click or select a row in the featuredatagrid the FeatureDataGrid_SelectionChanged event fires and passes the Parcel ID (of the selected row)...WORKS GREAT

In 3.0 the code fires when the spatial selection is made the featuredatagrid is populated and the FeatureDataGrid_SelectionChanged fires even though a row is not selected.  If I select a row the event does fire but code inside my  foreach (var g in graphics) never fires

It seems like it is problem with the populating graphics list.

Dave
0 Kudos
DavidAshton
Frequent Contributor
After doing some more test the in 3.0 api my for loop does fire but only after the first row selection change and it reports the previous Parcel ID.  Hopefully I can explain this better.

If I select several parcels and populate the featuredatagrid with several records.

First I click a row in the datagrid and the  FeatureDataGrid_SelectionChanged event fires but there are no graphics in the list so the code never moves inside the for loop.

My second row click/selection and everyone after this fires the  FeatureDataGrid_SelectionChanged event and the code inside the for loop gets executed but when it reports back the apn (parcel id) it reports the apn of the previous row click.

As I stated before my code didn't change from 2.1 to 3.0 so I'm not sure what happen and what to do...Can you help?

Thanks Dave


 
var graphics = (sender as ESRI.ArcGIS.Client.Toolkit.FeatureDataGrid).SelectedGraphics;
           
 foreach (var g in graphics)
            {
                // get id 
                var id = g.Attributes["APN"];

                string apn10 = (string)id;

                IDValue.Text = apn10;
                

                // TODO: retrieve outside data for this id
                //    PARCELIDPASS.Text = string.Format("The ParcelID passed is {0}", id);
                PARCELIDPASS.Text = apn10;
                break;
                
            }
0 Kudos
DavidAshton
Frequent Contributor
I just wanted to follow up with some more information in hopes someone will respond and shed some light on my issue.

As stated I originally built my project with API 2.1 and everything worked great. Now I''ve test the exact same code in 2.3 API and 3.0 API and they are both not working or responding differently.

As stated earlier this code in 2.1 passes the correct information on the first FDG row click (selection change)

 private void QueryDetailsDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)

{
if (QueryDetailsDataGrid.SelectedItem != null) I had to added this if statement because in the 2.1 API the SelectionChange event doesn't fire/excute when the FDG is first populated but it does in 2.3. and 3.0. In 2.1 it doesn't excute until and record is selected/clicked in the FDG.
{
var graphics = (sender as FeatureDataGrid).SelectedGraphics;
foreach (var g in graphics)  First click on a row in FDG in 2.1 g gets populated and the code inside the for is excuted but it is not until the second click/ selection change of the FDG in 2.3 and 3.0 that makes this work.
{
// get id
var id = g.Attributes["APN"];

string apn10 = (string)id;

IDValue.Text = apn10;

MessageBox.Show(apn10); In 2.3 and 3.0 it is always reporting the previous row selected not sure why I think because of the problem above.


PARCELIDPASS.Text = apn10;

}
}

Thanks in advance for looking and helping.

Dave
0 Kudos
DavidAshton
Frequent Contributor
Still working on this horrible issue...hoping someone might take a look and get me going in a new direction.  I've rewrote the code over and over and it just doesn't work properly.

Dave
0 Kudos
DavidAshton
Frequent Contributor
Now I"ve started over.  I took the TabbedRibbon Template commented out the code for the DataGrid x:Name="QueryDetailsDataGrid"
and added code to use a FeatureDataGrid = MyFDG instead.  I added a SelectionChanged="MyDataGrid_SelectionChanged" Event and I'm still running into the same issue.  I know the selection change event is firing correctly so it is not a problem with that event but a problem with my code.  I'm attaching the zip file with the xaml and C# Main Pages in hopes someone can look at.  You can down load the tabbed ribbon template and swap out my xaml and C# page with the originals and should be rockin,  but in short (for the third or fourth time) here's the deal:

Below is my code in question and on the First click on a row in FDG the code inside the for loop dose not execute but on the second click/ selection change of the row in the FDG it gets executed but the message box displays the previous state name (from the first click/selection)

private void MyDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
                {
                  
                    
                    if (MyDataGrid.SelectedItem != null)
                    {

                        if (MyDataGrid.SelectedGraphics.Count == 1)
                        {
                            var graphics = (sender as FeatureDataGrid).SelectedGraphics;
                            foreach (var g in graphics)
                            {
                                // get id 
                                var id = g.Attributes["STATE_NAME"];

                                StateName = (string)id;
                               

                                break;
                            }
                            MessageBox.Show(StateName);

                        }
                    }
                }


Dave
0 Kudos