Completed
Last Updated: 29 Nov 2016 10:37 by ADMIN
ADMIN
Hristo
Created on: 11 Nov 2016 16:29
Category: GridView
Type: Feature Request
0
ADD. RadGridView - the excel-like popup is not populated with distinct values for the child templates when the grid is setup in hierarchy using load on demand
Workaround: create a custom RadListFilterPopup
private void radGridView1_FilterPopupRequired(object sender, FilterPopupRequiredEventArgs e)
{
    e.FilterPopup = new MyRadListFilterPopup(e.Column);
}

public class MyRadListFilterPopup : RadListFilterPopup
{
    public MyRadListFilterPopup(GridViewDataColumn dataColumn)
        : base(dataColumn, false)
    { }

    protected override RadListFilterDistinctValuesTable GetDistinctValuesTable()
    {
        if (this.DataColumn.OwnerTemplate.HierarchyLevel == 0)
        {
            return base.GetDistinctValuesTable();    
        }

        GridViewColumnValuesCollection distinctValues = this.GetDistinctValuesWithFilter(this.DataColumn);
        RadListFilterDistinctValuesTable valuesTable = new RadListFilterDistinctValuesTable();
        valuesTable.FormatString = this.DataColumn.FormatString;
        valuesTable.DataConversionInfoProvider = this.DataColumn;

        GridViewComboBoxColumn comboBoxColumn = this.DataColumn as GridViewComboBoxColumn;
        if (comboBoxColumn != null && !String.IsNullOrEmpty(comboBoxColumn.ValueMember))
        {
            foreach (object value in distinctValues)
            {
                if (value != null && value != System.DBNull.Value)
                {
                    object rowValue = value;
                    object lookupValue = ((GridViewComboBoxColumn)this.DataColumn).GetLookupValue(value);

                    if (comboBoxColumn.FilteringMode == GridViewFilteringMode.DisplayMember)
                    {
                        rowValue = lookupValue;
                    }

                    if (lookupValue != null)
                    {
                        valuesTable.Add(lookupValue.ToString(), rowValue);
                    }
                }
            }
        }
        else
        {
            foreach (object value in distinctValues)
            {
                valuesTable.Add(value);
            }
        }

        return valuesTable;
    }

    private GridViewColumnValuesCollection GetDistinctValuesWithFilter(GridViewDataColumn column)
    {
        GridViewColumnValuesCollection distinctValues = new GridViewColumnValuesCollection();
        int count = column.OwnerTemplate.ExcelFilteredColumns.Count;
        if ((count > 0 &&
            column == column.OwnerTemplate.ExcelFilteredColumns[count - 1]) || column.OwnerTemplate.HierarchyLevel > 0)
        {
            if (count == 1 || column.OwnerTemplate.HierarchyLevel > 0)
            {
                int index = column.Index;
                if (index >= 0)
                {
                    IList<GridViewRowInfo> templateRows = column.OwnerTemplate.Rows;
                    if (templateRows.Count == 0 && column.OwnerTemplate.Parent != null && column.OwnerTemplate.HierarchyLevel > 0)
                    {
                        templateRows = new List<GridViewRowInfo>();
                        GridViewInfo templateViewInfo = column.OwnerTemplate.MasterViewInfo;
                        for (int i = 0; i < column.OwnerTemplate.Parent.Rows.Count; i++)
                        {
                            GridViewRowInfo parentRow = column.OwnerTemplate.Parent.Rows[i];
                            ((List<GridViewRowInfo>)templateRows).AddRange(column.OwnerTemplate.HierarchyDataProvider.GetChildRows(parentRow, templateViewInfo));
                        }
                    }
                    
                    foreach (GridViewRowInfo row in templateRows)
                    {
                        object cellValue = row.Cells[index].Value;
                        if (!distinctValues.Contains(cellValue))
                        {
                            distinctValues.Add(cellValue);
                        }
                    }
                    if (distinctValues.Count > 0)
                    {
                        return distinctValues;
                    }
                }
            }
        }

        return distinctValues;
    }
}
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments