RadListBox Disable Left / Right Arrow

2 posts, 0 answers
  1. Jonathan Ruckert
    Jonathan Ruckert avatar
    11 posts
    Member since:
    May 2005

    Posted 26 Oct 2009 Link to this post

    I have a situation where we have 2 RadListBoxes side by side, however I need the right and left arrow to jump between the 2 without firing the OnSelectedIndexChanged event (I only want this to occur on the down and up arrow).

    I have tried calling the PreviewKeyDown method, and the KeyDown method but as I have found, the SelectedIndexChanged event gets fired first, so changing the second list when I don't want it to.

    Any ideas?

    Cheers,
    Jonathan
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 29 Oct 2009 Link to this post

    Hi Jonathan Ruckert,

    Thank you for writing.

    In order to achieve the desired behavior you need to subclass RadListBox and override the OnKeyDown method. In the custom class you will check for left or right arrow keys, implement your logic and return without calling the base implementation.
    Here is the skeleton of the new list box class:
    public class MyListBox : RadListBox
    {
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
            {
                // Implement custom logic here.
     
                return;
            }
     
            base.OnKeyDown(e);
        }
     
        public override string ThemeClassName
        {
            get
            {
                return typeof(RadListBox).FullName;
            }
            set
            {
                base.ThemeClassName = value;
            }
        }
    }
    The ThemeClassName overridden property is necessary for the theming mechanism to work properly.

    Please write again if you have other questions.

    All the best,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top