This is a migrated thread and some comments may be shown as answers.

RadListBox Disable Left / Right Arrow

1 Answer 145 Views
ComboBox and ListBox (obsolete as of Q2 2010)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jonathan Ruckert
Top achievements
Rank 1
Jonathan Ruckert asked on 27 Oct 2009, 02:34 AM
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

1 Answer, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 29 Oct 2009, 05:50 PM
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.
Tags
ComboBox and ListBox (obsolete as of Q2 2010)
Asked by
Jonathan Ruckert
Top achievements
Rank 1
Answers by
Victor
Telerik team
Share this question
or