Filtering with MultiColumn not work

13 posts, 2 answers
  1. Pham
    Pham avatar
    7 posts
    Member since:
    Aug 2012

    Posted 18 Apr 2012 Link to this post

    Hi, Telerik team.

    I use Telerik Winform Q1 2012
    I set property AutoFilter = true and FilterDescriptors  i set it filter on multicolumn with FilterOperator.Contains . When key press it auto filter then i select one row in EditorControl but SelectedValue set a wrong value.

    I try to customize code in Demo Example's Telerik and have the same problem.

    In namespace Telerik.Examples.WinControls.Editors.ComboBox.MultiColumnComboBox i customize Onload Method.
              protected override void OnLoad(EventArgs e)
              {
                   base.OnLoad(e);
     
                NorthwindDataSet nwindDataSet = new NorthwindDataSet();
                CustomersTableAdapter customersTableAdapter = new CustomersTableAdapter();
                customersTableAdapter.Fill(nwindDataSet.Customers);
     
                this.radMultiColumnComboBox1.DataSource = nwindDataSet.Customers;
     
     
                //New My Code
                for (int i = 0 ; i < this.radMultiColumnComboBox1.EditorControl.Columns.Count ; i++)
                {
                    var item = this.radMultiColumnComboBox1.EditorControl.Columns[i];
                    string tmp= item.FieldName;
                    FilterDescriptor descriptor = new FilterDescriptor(tmp ,FilterOperator.Contains ,null);             
                    this.radMultiColumnComboBox1.EditorControl.FilterDescriptors.Add(descriptor);
                    this.radMultiColumnComboBox1.EditorControl.FilterDescriptors.LogicalOperator = FilterLogicalOperator.Or;
                }        
                 
                //Old code
                //FilterDescriptor descriptor = new FilterDescriptor(this.radMultiColumnComboBox1.DisplayMember ,FilterOperator.StartsWith ,string.Empty);
                //this.radMultiColumnComboBox1.EditorControl.FilterDescriptors.Add(descriptor);
     
                this.radMultiColumnComboBox1.DropDownStyle = RadDropDownStyle.DropDown;
                // Filtering END
            }
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 20 Apr 2012 Link to this post

    Hello Pham,

    Thank you for writing.

    This issue is already logged in our PITS system . You can vote for it here. Meanwhile, you can use the work around provided in my enclosed project.

    I hope that you find this information useful. Let us know if you have any other questions or suggestions.

    Kind regards,
    Svett
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Pham
    Pham avatar
    7 posts
    Member since:
    Aug 2012

    Posted 08 May 2012 Link to this post

    Hi, Svett
    Thank you for writting very much.
    Following yours code i fixed this error.With the same code above , But i don't know why when I type 'a' character and Press Enter key RadMultiColumnCombobox's Popupform is close and set Selectedvalue is CurrentRow of EditorControl. But if i type 'av' or 'b'  or 'bl' .. ect then i press Enter key popup does not close.
    You can use my code for test it in Telerik.Examples.WinControls.Editors.ComboBox.MultiColumnComboBox.

    I want when i type 'av' or 'b'  or 'bl' .. ect then i press Enter key popup will close  and Text  not change.
    i hope you can help me.Thanks.

    Thank you for reading.
  5. Svett
    Admin
    Svett avatar
    728 posts

    Posted 10 May 2012 Link to this post

    Hi Pham,

    You can overcome this behavior by extending the control in the following manner:
    public class CustomMCCB : RadMultiColumnComboBox
    {
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadMultiColumnComboBox).FullName;
            }
            set
            {
                base.ThemeClassName = value;
            }
        }
     
        protected override RadMultiColumnComboBoxElement CreateMultiColumnComboBoxElement()
        {
            return new CustomMCCBElement();
        }
    }
     
    public class CustomMCCBElement : RadMultiColumnComboBoxElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadMultiColumnComboBoxElement);
            }
        }
     
        protected override void ProcessReturnKey(System.Windows.Forms.KeyEventArgs e)
        {
            string text = this.Text;
            GridViewRowInfo newCurrentRow = this.FindItemExact(this.Text) as GridViewRowInfo;
     
            base.ProcessReturnKey(e);
     
            if (this.AutoFilter && newCurrentRow == null)
            {
                this.Text = text;
            }
     
        }
    }

    Let me know how this works for you.

    All the best,
    Svett
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  6. HowieD
    HowieD avatar
    8 posts
    Member since:
    Jun 2012

    Posted 28 Jun 2012 Link to this post

    Hi Svett,

    I'm facing the same problem as Pham but the solution you provided didn't work for me.
    The behaviour is exact the same as before.

    Is there an other way to get rid of this problem?

    Kind Regards
    HowieD
  7. Hsan
    Hsan avatar
    2 posts
    Member since:
    Jul 2012

    Posted 02 Jul 2012 Link to this post

    Hello, 
    I 'd like to know how to filter multiple data in telerik mulitcombobox in widows.I'd like to search multiple data from multicombobox.Please reply me.
  8. HowieD
    HowieD avatar
    8 posts
    Member since:
    Jun 2012

    Posted 03 Jul 2012 Link to this post

    Hello,

    is there anybody who can help on this issue since this is a real showstopper!!!

    Kind Regards
    HowieD
  9. Svett
    Admin
    Svett avatar
    728 posts

    Posted 03 Jul 2012 Link to this post

    Hi Guys,

    @Hsan: Presently, the RadMultiColumnComboBox editor support auto-filtering operation, which is not auto-complete functionality. You can read more about this feature in the online documentation.

    @Herbert: If you want to close the popup, when the text does not match item in your data source, you can changed the CustomMCCBElement in that way:

    public class CustomMCCBElement : RadMultiColumnComboBoxElement
    {
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadMultiColumnComboBoxElement);
            }
        }
     
        protected override void ProcessReturnKey(System.Windows.Forms.KeyEventArgs e)
        {
            string text = this.Text;
            GridViewRowInfo newCurrentRow = this.FindItemExact(this.Text) as GridViewRowInfo;
     
            base.ProcessReturnKey(e);
     
            if (this.AutoFilter && newCurrentRow == null)
            {
                this.Text = text;
                this.ClosePopup();
            }
     
        }
    }

    If the proposed solution does not fit you requirements, could you open support ticket with enclosed project and illustration of the exact steps that produces the issue? We will look into it for you.

    Kind regards,
    Svett
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  10. HowieD
    HowieD avatar
    8 posts
    Member since:
    Jun 2012

    Posted 03 Jul 2012 Link to this post

    Hi Svett,

    I think what you're missing is the fact that there are matching items but they're are not selected as Pham noted in his post on May 8 2012.

    Also you sait that there is an existing ticekt in your PITS System. So why opening a new one, since this seems to be a known problem? Also steps to reproduce the issue are clear as well.

    I would like to have a solution/workaround as soon as possible! We cannot wait until you may fix this error in one of your release in the months or years!

    Kind regards
    HowieD
  11. Svett
    Admin
    Svett avatar
    728 posts

    Posted 04 Jul 2012 Link to this post

    Hello Herbert,

    It seems that I misunderstood the way I can reproduce the issue. Could you give me exact steps that I should follow? I cannot provide a workaround without inspecting the exact scenario and determining what causes it.

    I did not create a new PITS item, because there is a existing one. 

    Thank you for your cooperation. I am looking forward to your reply.

    Regards,
    Svett
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  12. HowieD
    HowieD avatar
    8 posts
    Member since:
    Jun 2012

    Posted 05 Jul 2012 Link to this post

    Hi Svett,

    Here is a definition of our derived control
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
    using Telerik.WinControls;
    using Telerik.WinControls.Data;
     
    namespace WindowsFormsApplication1
    {
        public partial class ContactCode : RadMultiColumnComboBox
        {
            private bool isGridInitialized;
            private string enteredText;
            private enDropDownStates dropstate = enDropDownStates.Closed;
            private List<dicKontaktCode> kontaktCodes;
     
            #region Public Enums
            public enum enDropDownStates
            {
                Closed,
                Open
            }
            #endregion
     
            #region Public Events
            public event EventHandler KontaktCodeSelected;
     
            protected void RaiseKontaktCodeSelected()
            {
                if (KontaktCodeSelected != null)
                    KontaktCodeSelected(this, new EventArgs());
            }
            #endregion
     
            #region Constructors
            public ContactCode()
            {
                InitializeComponent();
                InitVariables();
                InitControl();
            }
     
            private void InitVariables()
            {
                isGridInitialized = false;
            }
     
            private void InitControl()
            {
                this.MultiColumnComboBoxElement.AutoCompleteMode = AutoCompleteMode.Append; // .Suggest;
                this.MultiColumnComboBoxElement.DropDownWidth = 300;
                this.MultiColumnComboBoxElement.DropDownHeight = 200;
                this.MultiColumnComboBoxElement.DropDownMinSize = new Size(300, 200);
                this.MultiColumnComboBoxElement.TextBoxElement.KeyDown += new KeyEventHandler(textBoxElement_KeyDown);
                this.SelectedIndexChanged += new EventHandler(this_SelectedIndexChanged);
                this.SelectedValueChanged += new EventHandler(this_SelectedValueChanged);
                this.EditorControl.FilterChanged += new GridViewCollectionChangedEventHandler(EditorControl_FilterChanged);
     
                this.EditorControl.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
                this.EditorControl.AutoGenerateColumns = false;
                this.EditorControl.EnableFiltering = true;
     
                base.AutoFilter = true;
                base.DropDownStyle = RadDropDownStyle.DropDown;
                base.DisplayMember = "KontaktCode";
                base.Text = string.Empty;
            }
     
            void EditorControl_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
            {
                int test = e.NewStartingIndex;
            }
     
            void this_SelectedValueChanged(object sender, EventArgs e)
            {
                int test = this.SelectedIndex;
            }
     
            private void this_SelectedIndexChanged(object sender, EventArgs e)
            {
                int test = this.SelectedIndex;
            }
            #endregion
     
            #region Public Properties
            [Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            EditorBrowsable(EditorBrowsableState.Never)]
            public new bool AutoFilter
            {
                get { return base.AutoFilter; }
            }
     
            [Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            EditorBrowsable(EditorBrowsableState.Never)]
            public new RadDropDownStyle DropDownStyle
            {
                get { return base.DropDownStyle; }
            }
     
            [Browsable(true),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            EditorBrowsable(EditorBrowsableState.Never)]
            public new string DisplayMember
            {
                get { return base.DisplayMember; }
            }
     
            [Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            EditorBrowsable(EditorBrowsableState.Never)]
            public dicKontaktCode SelectedKontaktCode
            {
                get
                {
                    if (this.EditorControl.CurrentRow != null)
                    {
                        return this.EditorControl.CurrentRow.DataBoundItem as dicKontaktCode;
                    }
                    else
                    {
                        return null;
                    }
                }
                set
                {
                    SetSelectedItem(value);
                }
            }
     
            [Browsable(false),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
            EditorBrowsable(EditorBrowsableState.Never)]
            public Guid SelectedKontaktCodeID
            {
                get
                {
                    if (this.EditorControl.CurrentRow != null)
                    {
                        return (this.EditorControl.CurrentRow.DataBoundItem as dicKontaktCode).KontaktCodeId;
                    }
                    else
                    {
                        return Guid.Empty;
                    }
                }
                set
                {
                    SetSelectedItem(value);
                }
            }
     
            [Browsable(false)]
            public enDropDownStates DropDownState
            {
                get { return dropstate; }
            }
     
            #endregion
     
            #region Public Methods
            public void Clear()
            {
                this.SelectedIndex = -1;
                this.EditorControl.CurrentRow = null;
                this.Text = string.Empty;
            }
     
            public void Init()
            {
                if (!isGridInitialized)
                {
                    InitGridColumnsAndFilters();
                    isGridInitialized = true;
                }
     
                dicKontaktCode selectedItem = null;
     
                if (this.EditorControl.CurrentRow != null)
                {
                    selectedItem = this.EditorControl.CurrentRow.DataBoundItem as dicKontaktCode;
                }
     
                kontaktCodes = GetKontaktCodesAll();
                this.DataSource = kontaktCodes;
     
                if (this.DataSource != null)
                {
                    SetSelectedItem(selectedItem);
                }
            }
            #endregion
     
            #region Overrided Methods
            protected override void OnSelectedIndexChanged(EventArgs e)
            {
                base.OnSelectedIndexChanged(e);
                RaiseKontaktCodeSelected();
            }
            #endregion
     
            #region Events
            private void textBoxElement_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Enter)
                {
                    RadTextBoxElement textBoxElement = sender as RadTextBoxElement;
                    if (textBoxElement != null)
                    {
                        enteredText = textBoxElement.Text;
                    }
                }
            }
     
            protected override void OnDropDownClosed(RadPopupClosedEventArgs e)
            {
                dropstate = enDropDownStates.Closed;
            }
     
            protected override void OnDropDownOpened(EventArgs e)
            {
                dropstate = enDropDownStates.Open;
            }
     
            #endregion
     
            #region Private Methods
            private void InitGridColumnsAndFilters()
            {
                GridViewTextBoxColumn newColumn;
                FilterDescriptor newfilter;
     
                this.EditorControl.FilterDescriptors.Clear();
                this.MultiColumnComboBoxElement.Columns.Clear();
     
                // init grid
                newColumn = new GridViewTextBoxColumn();
                newColumn.Name = "KontaktCodeKurz";
                newColumn.HeaderText = "Kurzbez.";
                newColumn.FieldName = "KontaktCodeKurz";
                newColumn.HeaderTextAlignment = ContentAlignment.MiddleCenter;
                newColumn.TextAlignment = ContentAlignment.MiddleLeft;
                newColumn.Width = 95;
                this.MultiColumnComboBoxElement.Columns.Add(newColumn);
     
                newColumn = new GridViewTextBoxColumn();
                newColumn.Name = "KontaktCode";
                newColumn.HeaderText = "Langbezeichnung";
                newColumn.FieldName = "KontaktCode";
                newColumn.HeaderTextAlignment = ContentAlignment.MiddleCenter;
                newColumn.TextAlignment = ContentAlignment.MiddleLeft;
                newColumn.Width = 190;
                this.MultiColumnComboBoxElement.Columns.Add(newColumn);
     
                // init filter
                newfilter = new FilterDescriptor();
                newfilter.PropertyName = "KontaktCodeKurz";
                newfilter.IsFilterEditor = true;
                newfilter.Operator = FilterOperator.Contains;
                this.EditorControl.MasterTemplate.FilterDescriptors.Add(newfilter);
     
            }
     
            private void SetSelectedItem(dicKontaktCode selectedItem)
            {
                Guid selectedItemID = (selectedItem == null ? Guid.Empty : selectedItem.KontaktCodeId);
                SetSelectedItem(selectedItemID);
            }
     
            private void SetSelectedItem(Guid selectedItemID)
            {
                if (this.DataSource == null)
                {
                    return;
                }
     
                if (selectedItemID == Guid.Empty)
                {
                    this.SelectedIndex = -1;
                }
     
                GridViewRowInfo row = this.EditorControl.Rows.FirstOrDefault(p => (p.DataBoundItem as dicKontaktCode).KontaktCodeId == selectedItemID);
                if (row != null)
                {
                    row.IsSelected = true;
                    this.EditorControl.CurrentRow = row;
                    row.EnsureVisible();
                }
            }
     
            private List<dicKontaktCode> GetKontaktCodesAll()
            {
                List<dicKontaktCode> liKC = new List<dicKontaktCode>();
                dicKontaktCode kc;
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "Information";
                kc.KontaktCodeKurz = "INFO";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "Conventus";
                kc.KontaktCodeKurz = "CO";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "SecondLevelHotline";
                kc.KontaktCodeKurz = "SLH";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "Kaution";
                kc.KontaktCodeKurz = "KAU";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "Installation";
                kc.KontaktCodeKurz = "INST";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "IDEA Interface";
                kc.KontaktCodeKurz = "IDEA";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "TestApp";
                kc.KontaktCodeKurz = "Test";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "Betatest";
                kc.KontaktCodeKurz = "BETA";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "Rückruf";
                kc.KontaktCodeKurz = "RR";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                kc = new dicKontaktCode();
                kc.KontaktCodeId = Guid.NewGuid();
                kc.KontaktCode = "Sperre";
                kc.KontaktCodeKurz = "Sperr";
                kc.Created = DateTime.Now;
                kc.CreatedBy = "System";
                liKC.Add(kc);
     
                return liKC;
            }
            #endregion
     
        }
    }
    Also you'll get the definition for dicKontaktCode Class.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
     
    namespace WindowsFormsApplication1
    {
        public class dicKontaktCode
        {
            #region Properties
            public Guid KontaktCodeId { get; set; }
            public string KontaktCode { get; set; }
            public string KontaktCodeKurz { get; set; }
            public DateTime Created { get; set; }
            public string CreatedBy { get; set; }
            public DateTime Changed { get; set; }
            public string ChangedBy { get; set; }
            public bool IsDeleted { get; set; }
            #endregion
        }
    }

    Now, if you have inserted this in a winforms project and added the control to a form do the following while debugging:
    - type 'r' twice in the edit element of the MultiColumnComboBox
    - Data will be filtered and 2 rows are shown
    - Since the first one seems to be selected and is also the desired row: hit the Enter/Return key.
    - Now we're facing the error: the filter is cleared, the edit element is also cleared and nothing is selected although the opposite is expected.

    Hope this description helps you to reproduce the error.

    Kind Regards
    HowieD
  13. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 10 Jul 2012 Link to this post

    Hi HowieD,

    The auto-filtering does not behave in the same manner as auto-complete functionality. Presently, the RadMultiColumnComboBox supports only auto filtering, which selects the current item only if the text fully matches an item in your data source. To achieve the desired behavior you should modify the custom control by suspending filter cleaning and the current row search algorithm. I am enclosing modified version of the code snippets that you have sent.

    Greetings,
    Svett
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  14. Answer
    Chris
    Chris avatar
    2 posts
    Member since:
    Feb 2013

    Posted 06 Mar 2013 Link to this post

    just add the below code on load

     Dim descriptor As New FilterDescriptor(Me.multicolumncombobox1.DisplayMember, FilterOperator.StartsWith, String.Empty)
            Me.multicolumncombobox1.EditorControl.FilterDescriptors.Add(descriptor)
            Me.multicolumncombobox1.DropDownStyle = RadDropDownStyle.DropDown
Back to Top
UI for WinForms is Visual Studio 2017 Ready