【问题标题】:How to sort the [include] entitycollection in Ria Silverlight如何在 Ria Silverlight 中对 [include] entitycollection 进行排序
【发布时间】:2012-03-19 20:06:34
【问题描述】:

我在 rowdetails 中有另一个数据网格的数据网格,但我无法对详细信息视图进行排序 我尝试了以下但没有成功:(

主数据网格按以下方式填充:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    NamskeidinDomConTxt = new Namskeidin_DomainContext();

    this.NamskeidinDomConTxt.Load(this.NamskeidinDomConTxt.GetNamskeidQuery(), LoadBehavior.RefreshCurrent, loadOperation =>
        {
            PagedCollectionView pcView = new PagedCollectionView(loadOperation.Entities);
            pcView.SortDescriptions.Add(new SortDescription("Heiti", ListSortDirection.Ascending));
            namskeidDataGrid.ItemsSource = pcView;
        }, null);
}

主数据网格的详细信息行中的数据网格按以下方式填充: 首先,我捕获以下事件并获取详细信息数据网格。

private void namskeidsHlutarDataGrid_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
        {
            verkefniDataGrid = (e.DetailsElement as FrameworkElement).FindName("VerkefniDataGrid") as DataGrid;
            Verkefni_DomConTxt = new Verkefni_DomainContext();
}

然后这个事件会触发,所以当我获得 id 时,我可以填写详细信息数据网格:

private void namskeidsHlutarDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

    DataGrid dataGrid = sender as DataGrid;
    var item = dataGrid.SelectedItem;
    if (item != null)
    {
        nHlutaId = ((Entity)item).GetIdentity().ToString();
        Verkefni_DomConTxt.Load(Verkefni_DomConTxt.GetVerkefniQuery().Where(v => v.NamskeidsHluta_ID == nHlutaId),
        LoadBehavior.RefreshCurrent, loadOperation =>
            {
                verkefniDataGrid.ItemsSource = loadOperation.Entities;
            }, null);
    }
}


private void GridName_RowDetailsVisibilityChanged(object sender, DataGridRowDetailsEventArgs e)
{
var dataGrid = (e.DetailsElement as FrameworkElement).FindName("detailsDataGrid") as DataGrid;
PagedCollectionView pcView = new PagedCollectionView(dataGrid.ItemsSource as IEnumerable);
pcView.GroupDescriptions.Clear();
pcView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
pcView.Refresh();
}

实际上有三个数据网格详细信息/详细信息 谁能帮我解决这个问题?

【问题讨论】:

    标签: silverlight datagrid ria


    【解决方案1】:

    您正在创建一个新的 PagedCollectionView,但您的 DataGrid 的 ItemsSource 仍绑定到普通的 IEnumerable。您需要将 ItemsSource 绑定到 PagedCollectionView。

    更新:因此,根据您更新的代码,您应该像加载父网格一样加载子网格。所以而不是:

    Verkefni_DomConTxt.Load(Verkefni_DomConTxt.GetVerkefniQuery().Where(v => v.NamskeidsHluta_ID == nHlutaId), LoadBehavior.RefreshCurrent, 
    loadOperation => { verkefniDataGrid.ItemsSource = loadOperation.Entities;}, null);
    

    您可以在此处创建数据视图并将项目源设置为指向它:

    Verkefni_DomConTxt.Load(Verkefni_DomConTxt.GetVerkefniQuery().Where(v => v.NamskeidsHluta_ID == nHlutaId), LoadBehavior.RefreshCurrent, 
    loadOperation => {
      PagedCollectionView pcView = new PagedCollectionView(loadOperation.Entities);          
      pcView.GroupDescriptions.Clear();          
      pcView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
      verkefniDataGrid.ItemsSource = pcView;
      }, null);
    

    然后摆脱试图创建视图的其他事件。

    【讨论】:

    • 您好,感谢您的回复。我曾尝试使用 PagedCollectionView pcView = dataGrid.ItemsSource 作为 PagedCollectionView 但返回 null。你能推荐一种方法来完成这个
    • 很难知道从哪里开始,因为您没有提供很多代码。 ItemsSource 绑定首先是如何设置的?
    • 嗨,布莱恩特,我在问题中添加了更多代码,希望对您有所帮助,谢谢
    猜你喜欢
    • 2011-09-03
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多