Completed
Last Updated: 28 May 2015 06:47 by Svetlin
Svetlin
Created on: 23 Feb 2012 10:53
Category: GridView
Type: Bug Report
3
FIX. RadGridView - filtering in RadMultiColumnComboBox editor does not work appropriately if the AutoFilter property is false.
Workaround: use the following custom editor:

using System;
using Telerik.WinControls.UI;

namespace radGridView_MultipleFilters
{
    public class CustomRadMultiColumnComboBoxElement : RadMultiColumnComboBoxElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadMultiColumnComboBoxElement);
            }
        }

        public GridViewDataColumn DisplayColumn
        {
            get
            {
                string displayMember = this.DisplayMember;
                if (string.IsNullOrEmpty(displayMember))
                {
                    for (int i = 0; i < this.MultiColumnPopupForm.EditorControl.Columns.Count; i++)
                    {
                        if (this.MultiColumnPopupForm.EditorControl.Columns[i].DataType == typeof(string))
                        {
                            displayMember = this.MultiColumnPopupForm.EditorControl.Columns[i].FieldName;
                            break;
                        }
                    }
                    if (this.MultiColumnPopupForm.EditorControl.Columns.Count > 0
                        && string.IsNullOrEmpty(displayMember))
                    {
                        displayMember = this.MultiColumnPopupForm.EditorControl.Columns[0].FieldName;
                    }
                }
                DisplayMember = displayMember;
                GridViewDataColumn[] columns = this.MultiColumnPopupForm.EditorControl.Columns.GetColumnByFieldName(displayMember);
                if (columns.Length > 0)
                {
                    return columns[0];
                }
                return null;
            }
        }

        protected override object FindItemExact(string text)
        {
            int index = this.FindItemIndexExact(text);

            if (index != -1)
            {
                return this.EditorControl.ChildRows[index];
            }

            return null;
        }

        protected override void SetActiveItem(string text)
        {
            int rowIndex = this.FindItemIndexExact(text);

            if (rowIndex != -1)
            {
                this.EditorControl.CurrentRow = this.EditorControl.ChildRows[rowIndex];
                this.Select(this.Text.Length, 0);
            }
        }

        protected override int FindItemIndexExact(string text)
        {
            GridViewRowInfo rowInfo = this.FindItemExact(text, this.DisplayColumn.Name);

            if (rowInfo != null)
            {
                return rowInfo.Index;
            }

            return -1;
        }

        protected override GridViewRowInfo FindItemExact(string text, string field)
        {
            GridViewDataColumn[] foundColumns = this.EditorControl.Columns.GetColumnByFieldName(field);
            if (foundColumns.Length > 0)
            {
                for (int i = 0; i < this.EditorControl.ChildRows.Count; i++)
                {
                    object element =
                        this.EditorControl.ChildRows[i].Cells[foundColumns[0].Name].Value;

                    string elementText = Convert.ToString(element);

                    if (!string.IsNullOrEmpty(elementText) && elementText.Equals(text,
                        this.EditorControl.MasterTemplate.CaseSensitive ? StringComparison.InvariantCulture : StringComparison.InvariantCultureIgnoreCase))
                    {
                        return this.EditorControl.ChildRows[i];
                    }
                }
            }
            return null;
        }
    }
}
0 comments