Suppress home and end keys during text input

3 posts, 0 answers
  1. Dave Wolf
    Dave Wolf avatar
    37 posts
    Member since:
    Feb 2006

    Posted 19 Jan 2018 Link to this post

    I'm trying to clear out the text entered in a RadDropdownlist while the popup is open by doing a "shift + home" to select all text but instead it causes the first dropdown item to get selected from the popup window.  Pressing the "end" key will select the last item from the list.  I've tried everything I could think of to suppress this but nothing seems to work. What can I do?
  2. Dimitar
    Admin
    Dimitar avatar
    2931 posts

    Posted 22 Jan 2018 Link to this post

    Hello Dave,

    The Home and End keys are handled in the DropDownPopupForm class. The following example shows how you can create a custom popup form and handle these keys:
    public class MyDropDownList : RadDropDownList
    {
        protected override RadDropDownListElement CreateDropDownListElement()
        {
            return new MyDropDownListElement();
        }
    }
     
    public class MyDropDownListElement : RadDropDownListElement
    {
        protected override RadPopupControlBase CreatePopupForm()
        {
            MyPopupForm form = new MyPopupForm(this);
            this.Popup = form;
           
            this.WirePopupFormEvents(this.Popup);
     
            return form;
        }
     
       
     
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadDropDownListElement);
            }
        }
    }
     
    public class MyPopupForm : DropDownPopupForm
    {
        public MyPopupForm(RadDropDownListElement ownerDropDownListElement)
            : base(ownerDropDownListElement)
        {
        }
     
        public override bool OnKeyDown(Keys keyData)
        {
            if ((keyData == Keys.Home || keyData == Keys.End))
            {
                return false;
            }
            return base.OnKeyDown(keyData);
        }
     
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Dave Wolf
    Dave Wolf avatar
    37 posts
    Member since:
    Feb 2006

    Posted 22 Jan 2018 in reply to Dimitar Link to this post

    Thank you, that's exactly what I was looking for. 

     

Back to Top