This is a migrated thread and some comments may be shown as answers.

Rad Multi Combo box multi-column filter

2 Answers 475 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Surya
Top achievements
Rank 1
Surya asked on 23 Mar 2016, 02:12 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Mar 2016, 10:47 AM
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 "", 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.
0
Surya
Top achievements
Rank 1
answered on 28 Mar 2016, 11:34 AM
Thanks for the solutions.Its worked for me.
Tags
MultiColumn ComboBox
Asked by
Surya
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Surya
Top achievements
Rank 1
Share this question
or