GridView with AutoCompleteEditor: Limiting token to a single value

3 posts, 1 answers
  1. Mimi
    Mimi avatar
    7 posts
    Member since:
    Dec 2018

    Posted 17 Dec 2018 Link to this post

    I've done some searching but was unable to find anything to help my specific case. I am using an AutoCompleteEditor class to enable drop down textboxes on my grid view, but I want to limit the token to 1 min and max. How can I do this? You may ask why I am using this instead of a ComboBoxColumn. The answer is: I have been instructed to not show any drop down arrows. 

    Here is the class that I've taken from forums:

      class AutoCompleteEditor : RadTextBoxControlEditor
        {
            protected override Telerik.WinControls.RadElement CreateEditorElement()
            {
                return new RadAutoCompleteBoxElement();
            }

            public override void OnKeyDown(System.Windows.Forms.KeyEventArgs e)
            {
                RadAutoCompleteBoxElement element = this.EditorElement as RadAutoCompleteBoxElement;

                if (element.IsAutoCompleteDropDownOpen)
                {
                    return;
                }

                base.OnKeyDown(e);
            }
        }

     

    I am trying to validate data entered into the cell, but it looks like end users are able to select multiple values. I want to completely disable this ability and allow only a single value to be selected.

    It would be much simpler to use a regular ComboBoxColumn, but I am unable to convince decision makers other wise.


  2. Answer
    Hristo
    Admin
    Hristo avatar
    1519 posts

    Posted 18 Dec 2018 Link to this post

    Hi Mimi,

    I can suggest using the GridViewComboBoxColumn with an enabled auto-complete and a hidden drop-down button. This way you will only have a single item selected, which will also be limited to the auto-complete data source. All you need to do is to handle the CellEditorInitialized event, please check my code snippet below: 
    private void RadGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
    {
        RadDropDownListEditor editor = e.ActiveEditor as RadDropDownListEditor;
        if (editor != null)
        {
            RadDropDownListEditorElement element = (RadDropDownListEditorElement)editor.EditorElement;
            element.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            element.ArrowButton.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
        }
    }

    I hope this will help. Let me know if you have other questions.

    Regards,
    Hristo
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Mimi
    Mimi avatar
    7 posts
    Member since:
    Dec 2018

    Posted 18 Dec 2018 in reply to Hristo Link to this post

    How simple. Thank you very much, this resolves a lot of issues. Thank you!
Back to Top