Rad Multi Combo box multi-column filter

3 posts, 1 answers
  1. Surya
    Surya avatar
    35 posts
    Member since:
    Nov 2011

    Posted 23 Mar Link to this post

    Hi,

    We have a combo box with 2 columns ( Lets say Code --> Display member and Description ) and added Composite filters in all visible columns :

                this.AutoFilter = true;

                if (MutipleColumnSearch)
                {
                    for (int i = 0; i < strVisiblecolumns.Length; i++)
                    {
                        FilterDescriptor visibleColFD = new FilterDescriptor(strVisiblecolumns[i], FilterOperator.Contains, null);
                        this.EditorControl.FilterDescriptors.Add(visibleColFD);
                    }
                    this.EditorControl.FilterDescriptors.LogicalOperator = FilterLogicalOperator.Or;
                }
                else
                {
                    FilterDescriptor filter = new FilterDescriptor();
                    filter.PropertyName = this.DisplayMember;
                    filter.Operator = FilterOperator.StartsWith;
                    this.EditorControl.MasterTemplate.FilterDescriptors.Add(filter);
                }

    Requirement :  On Searching , first it should check exact match with display member else contains search with rest of columns.

    For Example : if search with ES ( code ) it should list ES row as first row.

    Please find attached images.

  2. Answer
    Dess
    Admin
    Dess avatar
    1609 posts

    Posted 24 Mar Link to this post

    Hello Surya,

    Thank you for writing.

    RadMultiColumnComboBox performs filtering according to the entered text and iterates all rows to find the first row that meets the condition. As a result, this row is selected. Hence, when you type "es", the cell with value "United Arab Emirates" is the first cell that contains the searched text. This is correct behavior. If you need to change the selection after filtering, feel free to handle the MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.TextBoxControl.KeyUp event and select the desired row according to your custom logic:
    public Form1()
    {
        InitializeComponent();
        DataTable dt = new DataTable();
        dt.Columns.Add("Code", typeof(string));
        dt.Columns.Add("Description", typeof(string));
     
        dt.Rows.Add("AE", "United Arab Emirates");
        dt.Rows.Add("AN", "Netherlands Antilles");
        dt.Rows.Add("BD", "Bangladesh");
        dt.Rows.Add("BG", "Bulgaria");
        dt.Rows.Add("EE", "Estonia");
        dt.Rows.Add("ES", "Spain");
        this.radMultiColumnComboBox1.DataSource = dt;
        this.radMultiColumnComboBox1.DisplayMember = "Code";
        this.radMultiColumnComboBox1.EditorControl.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
     
        this.radMultiColumnComboBox1.AutoFilter = true;
        bool MutipleColumnSearch = true;
        CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();  
        compositeFilter.LogicalOperator = FilterLogicalOperator.Or;
        if (MutipleColumnSearch)
        {
            for (int i = 0; i < this.radMultiColumnComboBox1.Columns.Count; i++)
            {
                FilterDescriptor visibleColFD = new FilterDescriptor(this.radMultiColumnComboBox1.Columns[i].Name, FilterOperator.Contains, "");
                compositeFilter.FilterDescriptors.Add(visibleColFD);
            }
            this.radMultiColumnComboBox1.EditorControl.FilterDescriptors.Add(compositeFilter);
        }
        else
        {
            FilterDescriptor filter = new FilterDescriptor();
            filter.PropertyName = this.radMultiColumnComboBox1.DisplayMember;
            filter.Operator = FilterOperator.StartsWith;
            this.radMultiColumnComboBox1.EditorControl.MasterTemplate.FilterDescriptors.Add(filter);
        }
          
        this.radMultiColumnComboBox1.MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.TextBoxControl.KeyUp += TextBoxControl_KeyUp;
    }

    private void TextBoxControl_KeyUp(object sender, KeyEventArgs e)
    {
      foreach (GridViewRowInfo row in this.radMultiColumnComboBox1.EditorControl.Rows)
        {
            foreach (GridViewCellInfo cell in row.Cells)
            {
                if ((cell.Value + "").ToLower() == this.radMultiColumnComboBox1.Text.ToLower())
                {
                    this.radMultiColumnComboBox1.EditorControl.CurrentRow = row;
                    this.radMultiColumnComboBox1.MultiColumnComboBoxElement.TextBoxElement.TextBoxItem.TextBoxControl.SelectionStart
                        = this.radMultiColumnComboBox1.Text.Length;
                    return;
                }
            }
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Surya
    Surya avatar
    35 posts
    Member since:
    Nov 2011

    Posted 28 Mar in reply to Dess Link to this post

    Thanks for the solutions.Its worked for me.
Back to Top