当 ListChanged 时刷新 UltraGrid 的 GroupBy 对子带进行排序?

发布于 2024-08-01 23:20:34 字数 1663 浏览 11 评论 0原文

我正在使用 Infragistics 2009 第 1 卷。

我的 UltraGrid 绑定到业务对象“A”的 BindingList,该对象本身具有业务对象“B”的 BindingList 属性。 它导致有两个带:一个名为“BindingList`1”,另一个名为“ListOfB”,这要归功于货币管理器。

每当通过子业务对象和 INotifyPropertyChange 对子带执行更改时,我想刷新网格的 GroupBy 排序。

如果我按子带中的属性进行分组,该属性是布尔值(假设为“Active”),并且我使用此事件处理程序订阅绑定列表数据源上的事件 ListChanged:

void Grid_ListChanged(object sender, ListChangedEventArgs e)
{
    if (e.ListChangedType == ListChangedType.ItemChanged)
    {
        string columnKey = e.PropertyDescriptor.Name;
        if (e.PropertyDescriptor.PropertyType.Name == "BindingList`1")
        {
            ultraGrid.DisplayLayout.Bands[columnKey].SortedColumns.RefreshSort(true);
        }
        else
        {
            UltraGridBand band = ultraGrid.DisplayLayout.Bands[0];
            UltraGridColumn gc = band.Columns[columnKey];

            if (gc.IsGroupByColumn || gc.SortIndicator != SortIndicator.None)
            {
                band.SortedColumns.RefreshSort(true);
            }
            ColumnFilter cf = band.ColumnFilters[columnKey];
            if (cf.FilterConditions.Count > 0)
            {
                ultraGrid.DisplayLayout.RefreshFilters();
            }
        }
    }
}

调用 band.SortedColumns.RefreshSort(true) 但它当子带中的 Active 属性发生更改时,在 groupby 区域中会产生不可预测的结果:

如果三个活动对象中有一个对象变为非活动状态,则它会从:

  • Active : True (3 项)

变为:

  • Active : False (3 项)

而不是 (当我将列来回拖动到按区域分组时就是这种情况)

  • Active:False(1 项)

  • Active:True(2 项)< /p>

我做错了什么吗?

有没有办法在执行 RefreshSort(true); 时恢复行的展开状态? ?

I am using Infragistics 2009 vol 1.

My UltraGrid is bound to a BindingList of business objects "A" having themself a BindingList property of business objects "B". It results in having two bands: one named "BindingList`1", the other one "ListOfB" thanks to the currency manager.

I would like to refresh the GroupBy sort of the grid whenever a change is performed on the child band through the child business object and INotifyPropertyChange.

If I group by a property in the child band which is a boolean (let's say "Active") and I subscribe to the event ListChanged on the bindinglist datasource with this event handler:

void Grid_ListChanged(object sender, ListChangedEventArgs e)
{
    if (e.ListChangedType == ListChangedType.ItemChanged)
    {
        string columnKey = e.PropertyDescriptor.Name;
        if (e.PropertyDescriptor.PropertyType.Name == "BindingList`1")
        {
            ultraGrid.DisplayLayout.Bands[columnKey].SortedColumns.RefreshSort(true);
        }
        else
        {
            UltraGridBand band = ultraGrid.DisplayLayout.Bands[0];
            UltraGridColumn gc = band.Columns[columnKey];

            if (gc.IsGroupByColumn || gc.SortIndicator != SortIndicator.None)
            {
                band.SortedColumns.RefreshSort(true);
            }
            ColumnFilter cf = band.ColumnFilters[columnKey];
            if (cf.FilterConditions.Count > 0)
            {
                ultraGrid.DisplayLayout.RefreshFilters();
            }
        }
    }
}

the band.SortedColumns.RefreshSort(true) is called but It gives unpredictable results in the groupby area when the property Active is changed in the child band:

if one object out of three actives becomes inactive it goes from:

  • Active : True (3 items)

To:

  • Active : False (3 items)

Instead of (which is the case when I drag the column back and forth to the group by area)

  • Active : False (1 item)

  • Active : True (2 items)

Am I doing something wrong?

Is there a way to restore the expanded state of the rows when performing a RefreshSort(true); ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风流物 2024-08-08 23:20:34

对我来说听起来像是一个错误 - 你应该向 Infragistics 提交一个错误。

至于解决方法 - 这不是一个很好的解决方案,我还没有测试过它,但您始终可以尝试将排序(组)列保存到临时存储中,在带上使用 RefreshSort() ,然后重新应用排序-by(组)列,然后再次排序?

IE。 删除分组依据,然后重新应用。

令人讨厌,但它可能会让你摆脱困境。

Sounds like a bug to me - you should file one with Infragistics.

As to a workaround - this is not a nice solution and I haven't tested it but you could always try saving the sort-by (group) columns to a temp store, RefreshSort() on the band, then re-apply the sort-by (gorup) columns, and sort again?

ie. Remove group-by, then re-apply.

Nasty, but it might get you out of a bind.

待天淡蓝洁白时 2024-08-08 23:20:34

好吧,这就是我解决问题的方法

var ultraGridBand = this.ExperimentGrid.DisplayLayout.Bands[0];
            int nbGroup = ultraGridBand.Columns.All.Count(obj => ((UltraGridColumn) obj).IsGroupByColumn);
            //if (ultraGridBand.Columns.All.Any(obj => ((UltraGridColumn)obj).SortIndicator != SortIndicator.None)))
            if (nbGroup == 0)//no grouping
                ultraGridBand.SortedColumns.RefreshSort(true);
            else if (nbGroup > 0)
            {
                var expandedRows = new List<ExpandedRow>();
                var rowLevel1 = this.ExperimentGrid.DisplayLayout.Rows;
                ExtractExpandedRows(expandedRows, rowLevel1);
                ultraGridBand.SortedColumns.RefreshSort(true);
                SetExpandedRows(expandedRows, rowLevel1);
            }



    private static void SetExpandedRows(IEnumerable<ExpandedRow> expandedRows, RowsCollection rowLevel)
    {
        foreach (object obj in rowLevel.All)
        {
            var row = obj as UltraGridGroupByRow;
            if (row != null)
            {
                var expandedRow = expandedRows.FirstOrDefault(x => x.Value == row.ValueAsDisplayText);
                if (expandedRow != null)
                {
                    row.Expanded = expandedRow.IsExpanded;
                    SetExpandedRows(expandedRow.SubRows, row.Rows);
                }
            }
        }
    }

    private static void ExtractExpandedRows(ICollection<ExpandedRow> expandedRows, RowsCollection rowLevel)
    {
        foreach (object obj in rowLevel.All)
        {
            var row = obj as UltraGridGroupByRow;
            if(row != null)
            {
                var expandedRow = new ExpandedRow() { Value = row.ValueAsDisplayText, IsExpanded = row.Expanded };
                expandedRows.Add(expandedRow);
                ExtractExpandedRows(expandedRow.SubRows, row.Rows);
            }
        }
    }

这是包含信息的对象

class ExpandedRow
{
    public string Value { get; set; }
    public bool IsExpanded { get; set; }
    private readonly List<ExpandedRow> _subRows = new List<ExpandedRow>();
    public List<ExpandedRow> SubRows { get { return _subRows; } }
}

Well, this is how I manage to solve the problem

var ultraGridBand = this.ExperimentGrid.DisplayLayout.Bands[0];
            int nbGroup = ultraGridBand.Columns.All.Count(obj => ((UltraGridColumn) obj).IsGroupByColumn);
            //if (ultraGridBand.Columns.All.Any(obj => ((UltraGridColumn)obj).SortIndicator != SortIndicator.None)))
            if (nbGroup == 0)//no grouping
                ultraGridBand.SortedColumns.RefreshSort(true);
            else if (nbGroup > 0)
            {
                var expandedRows = new List<ExpandedRow>();
                var rowLevel1 = this.ExperimentGrid.DisplayLayout.Rows;
                ExtractExpandedRows(expandedRows, rowLevel1);
                ultraGridBand.SortedColumns.RefreshSort(true);
                SetExpandedRows(expandedRows, rowLevel1);
            }



    private static void SetExpandedRows(IEnumerable<ExpandedRow> expandedRows, RowsCollection rowLevel)
    {
        foreach (object obj in rowLevel.All)
        {
            var row = obj as UltraGridGroupByRow;
            if (row != null)
            {
                var expandedRow = expandedRows.FirstOrDefault(x => x.Value == row.ValueAsDisplayText);
                if (expandedRow != null)
                {
                    row.Expanded = expandedRow.IsExpanded;
                    SetExpandedRows(expandedRow.SubRows, row.Rows);
                }
            }
        }
    }

    private static void ExtractExpandedRows(ICollection<ExpandedRow> expandedRows, RowsCollection rowLevel)
    {
        foreach (object obj in rowLevel.All)
        {
            var row = obj as UltraGridGroupByRow;
            if(row != null)
            {
                var expandedRow = new ExpandedRow() { Value = row.ValueAsDisplayText, IsExpanded = row.Expanded };
                expandedRows.Add(expandedRow);
                ExtractExpandedRows(expandedRow.SubRows, row.Rows);
            }
        }
    }

And this is the object that contains the information

class ExpandedRow
{
    public string Value { get; set; }
    public bool IsExpanded { get; set; }
    private readonly List<ExpandedRow> _subRows = new List<ExpandedRow>();
    public List<ExpandedRow> SubRows { get { return _subRows; } }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文