Select Item with keyboard

2 posts, 0 answers
  1. Karsten
    Karsten avatar
    1 posts
    Member since:
    Sep 2013

    Posted 20 May 2014 Link to this post

    Hi,

    How can i select an item by pressing first character on keyboard. I can't find any property for this feature.

    Thanks and regards,
    Kasi
  2. Dess
    Admin
    Dess avatar
    1605 posts

    Posted 23 May 2014 Link to this post

    Hello Karsten,

    Thank you for writing.

    In order to select an item, pressing the key associated with the first letter of the item's text, it is appropriate to use the RadListView.PreviewKeyDown event. Here is a sample code snippet, demonstrating how to select the first found item, starting with the pressed key:
    Keys savedKey;
    Queue<ListViewDataItem> queue = new Queue<ListViewDataItem>();
     
    void radListView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyData != savedKey)
        {
            queue.Clear();
            foreach (ListViewDataItem item in radListView1.Items)
            {
                if (item.Text.StartsWith(e.KeyData.ToString()))
                {
                    queue.Enqueue(item);
                }
            }
     
            if (queue.Count > 0)
            {
                ListViewDataItem itemToSelect = queue.Dequeue();
                radListView1.SelectedItem = itemToSelect;
                queue.Enqueue(itemToSelect);
            }
            savedKey = e.KeyData;
        }
        else if (queue.Count > 0)
        {
            ListViewDataItem itemToSelect = queue.Dequeue();
            radListView1.SelectedItem = itemToSelect;
            queue.Enqueue(itemToSelect);
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top