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

Select Item with keyboard

1 Answer 191 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Karsten
Top achievements
Rank 1
Karsten asked on 20 May 2014, 11:39 AM
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

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 May 2014, 06:26 AM
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.
 
Tags
ListView
Asked by
Karsten
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or