[英]Silverlight 4 - related table datagrid display sorting
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. 我正在使用http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#QueryRelatedRecords中的示例代码将相关数据显示到数据网格中。 In my data I need the table to be sorted by the year (an attribute in my related table named "_year").
在我的数据中,我需要按年份对表进行排序(相关表中名为“ _year”的属性)。 I am not sure how to accomplish this - in the xaml or c#.
我不确定如何完成此操作-在xaml或c#中。 Below is my current code:
下面是我当前的代码:
xaml: 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#: 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!! 谢谢!!
This Code Should Help You May Be 此代码应该可以帮助您
bool SortDateAsc = true;
private void Date_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (SortDateAsc)
{
ObservableCollection<InvoicesDTO> a = new ObservableCollection<InvoicesDTO>(((ResolutionVM)this.DataContext).MainInvoiceList.OrderBy(oc => oc.FC_AGE));
((ResolutionVM)this.DataContext).MainInvoiceList = a;
InvoiceGrid.ItemsSource = ((ResolutionVM)this.DataContext).MainInvoiceList.ToList();
SortDateAsc = false;
((ResolutionVM)this.DataContext).RefreshSelctedInvoice();
}
else
{
ObservableCollection<InvoicesDTO> a = new ObservableCollection<InvoicesDTO>(((ResolutionVM)this.DataContext).MainInvoiceList.OrderByDescending(oc => oc.FC_AGE));
((ResolutionVM)this.DataContext).MainInvoiceList = a;
InvoiceGrid.ItemsSource = ((ResolutionVM)this.DataContext).MainInvoiceList.ToList();
SortDateAsc = true;
((ResolutionVM)this.DataContext).RefreshSelctedInvoice();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.