[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Prevent a listview to change selected item when key pressed

Posted on 2009-02-24
4
Medium Priority
?
582 Views
Last Modified: 2012-05-06
Hello

I am using a listview in VB.Net. When a key is pressed, by default the listview will select the item which first letter matches the key pressed. I would like to disable that, in order to be able to assign keys to certain actions. I can't see any obvious way to do it.  Would anyone know how to do this?

Thanks in advance
Charles
0
Comment
Question by:cm2187
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
lucius_the earned 200 total points
ID: 23725140
I am not sure you will be able to do this, but my idea is to try this:
Open event handlers for KeyPress, KeyDown and KeyUp events. In them set the "e.handled" property to True. This way you might tell the compiler that your event has been handled, amybe then it won't handle it itself.

Another option I have in mind, if the first one doesn't work, try to make a custom control. You custom control should inherit listview. Then override the KeyPress, KeyDown and KeyUp event. This way the original evets will not fire, and you might get what you want. Then use that control instead of the original listview.
0
 
LVL 4

Expert Comment

by:Thunder724
ID: 23726120
If the above does not work; you could opt for saving the currently selected index into a variable, and then set the selecteditems index after a keypress event in order to put it back.
0
 

Author Comment

by:cm2187
ID: 23728167
Hi

thanks for your responses. I've tried setting e.handled=true, but that still triggers the selection of the item.  

Even saving the selection manually and putting it back doesn't seem to help as VB selects the item only after the keypress sub is executed.

Charles

0
 

Author Comment

by:cm2187
ID: 23728324
ooops. Correction. I was trying e.handled on keydown. But if I do it on keypress, then the solution works.

thanks for your help!
Charles
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Loops Section Overview
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question