Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using the sample code from http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryRelatedRecords to display related data into a data grid. In my data I need the table to be sorted by the year (an attribute in my related table named "_year"). I am not sure how to accomplish this - in the xaml or c#. Below is my current code:

xaml:

                   <basics:TabControl Grid.Column="1" Margin="0,-1,0,0" Grid.RowSpan="2" Grid.ColumnSpan="2" Grid.Row="1" d:LayoutOverrides="GridBox">
                    <basics:TabItem x:Name="DataTab" Header="Data">
                        <Grid Background="#FFE5E5E5">
                            <slData:DataGrid x:Name="RelatedRowsDataGrid" AutoGenerateColumns="False" HeadersVisibility="All" 
                         BorderThickness="1" HorizontalScrollBarVisibility="Hidden" IsReadOnly="True" Margin="4,0,2,6" Height="127" VerticalAlignment="Bottom">
                                <slData:DataGrid.Columns>
                                    <slData:DataGridTextColumn CanUserSort="False"  Binding="{Binding Attributes[loc_id]}" Header="Location ID" FontWeight="Bold"/>
                                    <slData:DataGridTextColumn  CanUserSort="True" Binding="{Binding Attributes[_year]}" Header="Year"/>
                                    <slData:DataGridTextColumn CanUserSort="False" Binding="{Binding Attributes[adt]}" Header="ADT"/>
                                </slData:DataGrid.Columns>
                            </slData:DataGrid>
                        </Grid>
                    </basics:TabItem>
                    <basics:TabItem x:Name="ChartTab" Header="Chart">
                        <Grid Background="#FFE5E5E5">
                            <toolkit:Chart x:Name="MyChart2" Title="{Binding [PAGsde.DBO.TrafficCountNetwork.loc_id]}" 
                               esri:GraphicsLayer.MapTipHideDelay="0:0:3" Background="LightGray"  
                               LegendStyle="{StaticResource BlankLegendStyle}" TitleStyle="{StaticResource SmallTitleStyle}">
                                <toolkit:Chart.Series>
                                    <toolkit:ColumnSeries Title="ADT" IndependentValueBinding="{Binding Attributes[_year]}" 
                                              DependentValueBinding="{Binding Attributes[adt]}">
                                    </toolkit:ColumnSeries>
                                </toolkit:Chart.Series>
                            </toolkit:Chart>
                        </Grid>
                    </basics:TabItem>
                </basics:TabControl>

C#:

   private void SelectedRoadsTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
    {
        if (e.OldValue != null)
        {
            Graphic g = e.OldValue as Graphic;
            g.UnSelect();
            g.SetZIndex(0);
        }

        if (e.NewValue != null)
        {
            Graphic g = e.NewValue as Graphic;
            g.Select();
            g.SetZIndex(1);

            //Relationship query
            RelationshipParameter relationshipParameters = new RelationshipParameter()
            {
                ObjectIds = new int[] { Convert.ToInt32(g.Attributes[SelectedRoadsTreeView.Tag as string]) },
                OutFields = new string[] { "loc_id, count_id, _year, adt" },
                RelationshipId = 0,
                OutSpatialReference = Map.SpatialReference
            };

            queryTask.ExecuteRelationshipQueryAsync(relationshipParameters);

            MyChart2.Title = g.Attributes["TrafficCounts.COUNTUSER.%segment_master._street"];
        }
    }
    void QueryTask_ExecuteRelationshipQueryCompleted(object sender, RelationshipEventArgs e)
    {
        RelationshipResult pr = e.Result;
        if (pr.RelatedRecordsGroup.Count == 0)
        {
            RelatedRowsDataGrid.ItemsSource = null;
        }
        else
        {
            foreach (var pair in pr.RelatedRecordsGroup)
            {
                RelatedRowsDataGrid.ItemsSource = pair.Value;
                //?.SortDescriptions.Add(new System.ComponentModel.SortDescription("Attributes[_year]", System.ComponentModel.ListSortDirection.Ascending));

                ((ColumnSeries)MyChart2.Series[0]).ItemsSource = pair.Value;    //new KeyValuePair<int, int>[] { new KeyValuePair<int, int>(2005, 1200) };
            }
        }
    }

Thanks!!

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.