Refresh UltraGrid GroupBy Sort by Child Groups with ListChanged?

I am using Infragistics 2009 vol 1.

My UltraGrid is bound to the BindingList of business objects "A", which themselves have the BindingList property for business objects "B". This leads to the presence of two ranges: one of them is called "BindingList`1", the other - "ListOfB" thanks to the currency manager.

I would like to update GroupBy grid sorting whenever changes are made to a child group through a child business object and INotifyPropertyChange.

If I group a property in a child group that is logical (say, "Active"), and I subscribe to the ListChanged event on the data source of the binding list 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();
            }
        }
    }
}

.SortedColumns.RefreshSort(true), groupby, Active :

, :

  • Active: True (3 )

To:

  • : False (3 )

( , )

  • : False (1 )

  • Active: True (2 )

- ?

RefreshSort (true);

+3
2

- Infragistics.

- , , sort-by (group) temp, RefreshSort() , (gorup) ?

. , .

, .

0

,

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; } }
}
0

Source: https://habr.com/ru/post/1715059/


All Articles