Can't make the filter to work

6 posts, 0 answers
  1. coloboxp
    coloboxp avatar
    4 posts
    Member since:
    Apr 2007

    Posted 28 Sep Link to this post

    Hi

    I'm trying to use the MultiColumn ComboBox to allow users to search and select values from a flat table on the database, just it's not working and I've spent already the entire day trying combinations without success.

    This is the Class being binded:

    public class DocumentType
        {
            public int id { get; set; }
            public string Code { get; set; }
            public string Label { get; set; }
            public string Description { get; set; }
        }

    This is the Designe.cs code:

    //
    // cmbDocumentType
    //
    this.cmbDocumentType.AutoScroll = true;
    this.cmbDocumentType.AutoSize = true;
    this.cmbDocumentType.AutoSizeDropDownToBestFit = true;
    //
    // cmbDocumentType.NestedRadGridView
    //
    this.cmbDocumentType.EditorControl.AutoScroll = true;
    this.cmbDocumentType.EditorControl.BackColor = System.Drawing.SystemColors.Window;
    this.cmbDocumentType.EditorControl.Cursor = System.Windows.Forms.Cursors.Default;
    this.cmbDocumentType.EditorControl.EnableFastScrolling = true;
    this.cmbDocumentType.EditorControl.EnableGestures = false;
    this.cmbDocumentType.EditorControl.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
    this.cmbDocumentType.EditorControl.ForeColor = System.Drawing.SystemColors.ControlText;
    this.cmbDocumentType.EditorControl.ImeMode = System.Windows.Forms.ImeMode.NoControl;
    this.cmbDocumentType.EditorControl.Location = new System.Drawing.Point(0, 0);
     gridViewTextBoxColumn1.EnableExpressionEditor = false;
    gridViewTextBoxColumn1.FieldName = "Code";
    gridViewTextBoxColumn1.HeaderText = "Code";
    gridViewTextBoxColumn1.Name = "Code";
    gridViewTextBoxColumn1.Width = 58;
    gridViewTextBoxColumn2.EnableExpressionEditor = false;
    gridViewTextBoxColumn2.FieldName = "Label";
    gridViewTextBoxColumn2.HeaderText = "Label";
    gridViewTextBoxColumn2.Name = "Label";
    gridViewTextBoxColumn2.Width = 112;
    gridViewTextBoxColumn3.EnableExpressionEditor = false;
    gridViewTextBoxColumn3.FieldName = "Description";
    gridViewTextBoxColumn3.HeaderText = "Description";
    gridViewTextBoxColumn3.Name = "Description";
    gridViewTextBoxColumn3.Width = 357;
    this.cmbDocumentType.EditorControl.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] {
    gridViewTextBoxColumn1,
    gridViewTextBoxColumn2,
    gridViewTextBoxColumn3});
     
    //
    //
    //
    this.cmbDocumentType.EditorControl.AllowAddNewRow = false;
    this.cmbDocumentType.EditorControl.AllowCellContextMenu = false;
    this.cmbDocumentType.EditorControl.AllowColumnChooser = false;
    this.cmbDocumentType.EditorControl.AllowColumnReorder = false;
    this.cmbDocumentType.EditorControl.AllowDeleteRow = false;
    this.cmbDocumentType.EditorControl.AllowDragToGroup = false;
    this.cmbDocumentType.EditorControl.AllowEditRow = false;
    this.cmbDocumentType.EditorControl.AutoGenerateColumns = false;
    this.cmbDocumentType.EditorControl.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
     
    this.cmbDocumentType.EditorControl.EnableFiltering = true;
    this.cmbDocumentType.EditorControl.EnableGrouping = false;
    this.cmbDocumentType.EditorControl.EnableSorting = false;
    this.cmbDocumentType.EditorControl.ShowFilteringRow = false;
    //this.cmbDocumentType.EditorControl.ViewDefinition = tableViewDefinition1;
    this.cmbDocumentType.EditorControl.Name = "NestedRadGridView";
    this.cmbDocumentType.EditorControl.NewRowEnterKeyMode = Telerik.WinControls.UI.RadGridViewNewRowEnterKeyMode.None;
    this.cmbDocumentType.EditorControl.ReadOnly = true;
    this.cmbDocumentType.EditorControl.RightToLeft = System.Windows.Forms.RightToLeft.No;
    this.cmbDocumentType.EditorControl.ShowGroupPanel = false;
    this.cmbDocumentType.EditorControl.Size = new System.Drawing.Size(545, 31);
    this.cmbDocumentType.EditorControl.TabIndex = 0;
    this.cmbDocumentType.EnableAnalytics = false;
    this.cmbDocumentType.EnableGestures = false;
    this.cmbDocumentType.Location = new System.Drawing.Point(202, 7);
    this.cmbDocumentType.Name = "cmbDocumentType";
    this.cmbDocumentType.ShowItemToolTips = false;
    this.cmbDocumentType.Size = new System.Drawing.Size(271, 20);
    this.cmbDocumentType.TabIndex = 4;
    this.cmbDocumentType.TabStop = false;
    this.cmbDocumentType.ThemeName = "Office2007Black";
    this.cmbDocumentType.UseCompatibleTextRendering = false;

    And this is the code right at the end of the form's constructor:

    this.cmbDocumentType.AutoFilter = true;
     
    CompositeFilterDescriptor compositeFilter = new CompositeFilterDescriptor();
    compositeFilter.LogicalOperator = FilterLogicalOperator.Or;
     
    FilterDescriptor fdLabel = new FilterDescriptor("Label", FilterOperator.Contains, string.Empty);
    compositeFilter.FilterDescriptors.Add(fdLabel);
     
    FilterDescriptor fdDescription = new FilterDescriptor("Description", FilterOperator.Contains, string.Empty);
    compositeFilter.FilterDescriptors.Add(fdDescription);
     
    FilterDescriptor fdCode = new FilterDescriptor("Code", FilterOperator.Contains, string.Empty);
    compositeFilter.FilterDescriptors.Add(fdCode);
     
    this.cmbDocumentType.EditorControl.FilterDescriptors.Add(compositeFilter);
     
     
    RadGridView gridViewControl = this.cmbDocumentType.EditorControl;
    gridViewControl.MasterTemplate.AutoGenerateColumns = false;
    this.cmbDocumentType.MultiColumnComboBoxElement.DropDownAnimationEnabled = false;

    Later on, if by user input the combo is required, then I'm binding the data (list of DocumentType) from MemoryCache:

    if (this.cmbDocumentType.DataSource == null)
                    {
                            this.cmbDocumentType.DataSource = Globals.Cache.GetMobileDocumentTypes();
                            this.cmbDocumentType.Text = string.Empty;
                        }
                    }

    I don't know what's wrong, I've followed by the letter the documentation from here and still doesn't work.

    • Could you please tell me what's wrong?
    • Also, how can I highlight on the grid the text that the user has typed?
    • Can be changed the sort order once there is a match, let's say of 5 items containing the same text but a "SortPriority" property?

    Thank you for your time,

    Alejandro

     

  2. coloboxp
    coloboxp avatar
    4 posts
    Member since:
    Apr 2007

    Posted 28 Sep in reply to coloboxp Link to this post

    I couldn't find it on the documentation but also I would like to know if it's possible to do the search without diacritics, strip them out from the data on the DataBind and from the keyboard strokes.

    Thank you again.

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 30 Sep Link to this post

    Hello  Alejandro,

    Thank you for writing.

    First, you need to set the DisplayMember, then add the filter after the data source is set.

    The following article shows how you can highlight the results: Use custom filtering to search in all columns of RadMultiColumnComboBox.

    In addition, please note that typing in the text box is filtering the entire grid, so to sort the result you would need to sort the grid. Detailed information is available here: Custom Sorting.

    As to the diacritics striping at hand, you can use the CustomFiltering to manually generate the filtering results (instead of adding a composite filter just add one filter and then use the CustomFiltering event to check if the cell contains the value). This way you will have the cell value and the current text and you will be able to perform a custom comparison:
    private void EditorControl_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
    {
        string value = cmbDocumentType.Text;
        bool visible = false;
        foreach (GridViewCellInfo item in e.Row.Cells)
        {
            if (item.Value != null)
            {
                visible = item.Value.ToString().Contains(value);
            }
        }
        e.Visible = visible;
        e.Handled = true;
    }

    This will allow you to change the values and strip the diacritics. Here is an example for this: c# - Ignoring accented letters in string comparison - Stack Overflow.

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  5. coloboxp
    coloboxp avatar
    4 posts
    Member since:
    Apr 2007

    Posted 30 Sep in reply to Dimitar Link to this post

    Hi Dimitar

    Thank you very much for the reply,

    My original problem was that I couldn't filter, it didn't work. I was appliyng the filters before and after doing the databinding. It started to work when I did the databinding first and then applying the filters.

    Filtering as you described worked perfectly using one column, however I need to allow the user to (custom) search among the three columns while stripping out the diactitics. Can't be achieved using a composite filter?

    Regarding coloring and sorting, that's what I needed, thank you!

    Alejandro

  6. coloboxp
    coloboxp avatar
    4 posts
    Member since:
    Apr 2007

    Posted 30 Sep in reply to coloboxp Link to this post

    So I've made a (hopefully temporary) workaround but I hope there is a solution to allow custom filtering with composite filters.

    I've created a partial class (because the original class is created via Entity Framework) and added "clean" properties:

    public partial class DocumentType
    {
        public string CodeClean
        {
            get
            {
                return this.Code.RemoveDiacritics();
            }
        }
     
        public string LabelClean
        {
            get
            {
                return this.Label.RemoveDiacritics();
            }
        }
     
        public string DescriptionClean
        {
            get
            {
                return this.Description.RemoveDiacritics();
            }
        }
    }

     

  7. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 03 Oct Link to this post

    Hi  Alejandro,

    If you use the solution from my previous post (custom filtering), you do not need composite descriptors. When the user types, the CustomFiltering event will be fired for each row. This allows searching for a match in each column, not only the firs one. You can remove the Diacritics only when you are checking if the cell value contains the typed value and leave the data at it is. Would you check this solution and let me know how it works for your case. 

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready