473,790 Members | 3,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

KeyDown Event on a ListBox

I am building a hoem theatre app that is controlled by an IR Remote Control.
The Remote has some keys that map to "keyboard" commands (i.e. PageUp,
PageDown.).

In this VB.NET application I have a listbox control that I fill with songs
from the MediaPlayer Library (MediaCollectio n).
Now, my remote does not have "Tab" key or "up" and "down" arrow keys, but
it does have pageup, pagedown. I want the PageUp, PageDwn to "behave" like
the "up" and "down" arrow keys.

To do this, I tried the following:

Private Sub ListBox1_KeyDow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyEventA rgs) Handles ListBox1.KeyDow n
TextBox1.Text = e.KeyCode

Dim i As Integer = ListBox1.Select edIndex
If e.KeyCode = Keys.PageDown Then
i = i + 1
If i > ListBox1.Items. Count - 1 Then
i = 0
End If
ListBox1.Select edIndex = i
End If
End Sub
And similar code in there for the Keys.PageUp
The Problem is:

Even though the event is being fired, and the SelectedIndex is being changed
based on the If Statement, the "PageUp" command still executes after this
event handler completes. For instance, if the ListBox1 has 15 items, and
the SelectedIndex = 0 at the beginning. When the PageDown Key is pressed,
the even handler changes the SelectedIndex to 1. But, then immediately
after that, the Selected Index becomes 14 (because the PageDown command
processes).

Is there a way to "swallow" the PageUp/PageDown inside the KeyDown Event
Handler that I have written.

I am trying to avoid having to do a "Low Level Keyboard" Lock with the API.

Thanks.

-- Will Gillen
-- Gradekit.com


Nov 21 '05 #1
2 7260
Use the Handled property of the keyEventArgs of the KeyPress Event. If you
say e.handled=true, then .NET assumes you did whatever behavior needed to
be done. So you do your work in KeyDown and use e.handled=true in KeyPress
to prevent the listbox from processing the key.

Best of luck!

"Will Gillen" <gi******@nsuok .edu> wrote in
news:ut******** ******@TK2MSFTN GP15.phx.gbl:
I am building a hoem theatre app that is controlled by an IR Remote
Control. The Remote has some keys that map to "keyboard" commands
(i.e. PageUp, PageDown.).

In this VB.NET application I have a listbox control that I fill with
songs from the MediaPlayer Library (MediaCollectio n).
Now, my remote does not have "Tab" key or "up" and "down" arrow keys,
but it does have pageup, pagedown. I want the PageUp, PageDwn to
"behave" like the "up" and "down" arrow keys.

To do this, I tried the following:

Private Sub ListBox1_KeyDow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyEventA rgs) Handles ListBox1.KeyDow n
TextBox1.Text = e.KeyCode

Dim i As Integer = ListBox1.Select edIndex
If e.KeyCode = Keys.PageDown Then
i = i + 1
If i > ListBox1.Items. Count - 1 Then
i = 0
End If
ListBox1.Select edIndex = i
End If
End Sub
And similar code in there for the Keys.PageUp
The Problem is:

Even though the event is being fired, and the SelectedIndex is being
changed based on the If Statement, the "PageUp" command still executes
after this event handler completes. For instance, if the ListBox1 has
15 items, and the SelectedIndex = 0 at the beginning. When the
PageDown Key is pressed, the even handler changes the SelectedIndex to
1. But, then immediately after that, the Selected Index becomes 14
(because the PageDown command processes).

Is there a way to "swallow" the PageUp/PageDown inside the KeyDown
Event Handler that I have written.

I am trying to avoid having to do a "Low Level Keyboard" Lock with the
API.

Thanks.

-- Will Gillen
-- Gradekit.com



Nov 21 '05 #2
Thank you. That worked perfectly!
"cbDevelopm ent" <de*********@re move.700cb.net> wrote in message
news:Xn******** *************** ****@207.46.248 .16...
Use the Handled property of the keyEventArgs of the KeyPress Event. If you say e.handled=true, then .NET assumes you did whatever behavior needed to
be done. So you do your work in KeyDown and use e.handled=true in KeyPress to prevent the listbox from processing the key.

Best of luck!

"Will Gillen" <gi******@nsuok .edu> wrote in
news:ut******** ******@TK2MSFTN GP15.phx.gbl:
I am building a hoem theatre app that is controlled by an IR Remote
Control. The Remote has some keys that map to "keyboard" commands
(i.e. PageUp, PageDown.).

In this VB.NET application I have a listbox control that I fill with
songs from the MediaPlayer Library (MediaCollectio n).
Now, my remote does not have "Tab" key or "up" and "down" arrow keys,
but it does have pageup, pagedown. I want the PageUp, PageDwn to
"behave" like the "up" and "down" arrow keys.

To do this, I tried the following:

Private Sub ListBox1_KeyDow n(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyEventA rgs) Handles ListBox1.KeyDow n
TextBox1.Text = e.KeyCode

Dim i As Integer = ListBox1.Select edIndex
If e.KeyCode = Keys.PageDown Then
i = i + 1
If i > ListBox1.Items. Count - 1 Then
i = 0
End If
ListBox1.Select edIndex = i
End If
End Sub
And similar code in there for the Keys.PageUp
The Problem is:

Even though the event is being fired, and the SelectedIndex is being
changed based on the If Statement, the "PageUp" command still executes
after this event handler completes. For instance, if the ListBox1 has
15 items, and the SelectedIndex = 0 at the beginning. When the
PageDown Key is pressed, the even handler changes the SelectedIndex to
1. But, then immediately after that, the Selected Index becomes 14
(because the PageDown command processes).

Is there a way to "swallow" the PageUp/PageDown inside the KeyDown
Event Handler that I have written.

I am trying to avoid having to do a "Low Level Keyboard" Lock with the
API.

Thanks.

-- Will Gillen
-- Gradekit.com


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
9238
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I click on a row (withs will turn blue then) and then click on it again . Now if I press any key the event will fire (except for the arrow keys). I also tried to override the IsInputKey => no luck. I also tried to override the ProcessCmdKey => With...
4
8637
by: Anne | last post by:
hie again, i have 3 textbox and i would like the user to go to the next textbox by pressing the 'ENTER' key. i have tried using this: Private Sub txtRequestor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtRequestor.KeyDown If e.KeyCode = Keys.Enter Then SendKeys.Send("{TAB}")
4
7131
by: ShaneO | last post by:
I would like to handle the KeyUp & KeyDown events in the same event handler but can't find how to determine which event was fired - Private Sub ListBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _ Handles ListBox1.KeyUp, ListBox1.KeyDown If e.KeyValue = Keys.PageDown Or e.KeyValue = Keys.PageUp Or e.KeyValue = Keys.End Or e.KeyValue = Keys.Home Then
1
3310
by: fripper | last post by:
I have a VB 2005 windows app and I want to recognize keydown events. I have a form key down event handler but it does not get control when a key is depressed. In playing around I found that if I add a keydown event handler for some control on the form, say a textbox ... Private Sub txtBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBox.KeyDown) and then give that control focus the keydown...
0
1758
by: tony | last post by:
Hello!! I have a derived class called StringClassEditor which inherit from UITypeEditor listed below. Now to my question in method EditValue in this class I have this statement lb.KeyDown += new KeyEventHandler(ListBox_KeyDown); I have set a breakpoint in the event handler method ListBox_KeyDown but this method is never called. So this event KeyDown for control ListBox is never occuring.
3
5256
by: MLM450 | last post by:
I have a control that handles the KeyDown event but it does not seem to execute when a combination of keys is pressed - like CTRL+Z. If I press CTRL, it executes. If I press Z, it executes. But the handler does not see the combination. Now this control is contained within another control which is contained within another. The top most control does see the CTRL+Z. I can easily pass down the key info, but why does the nested control see...
3
7888
by: Luc The Perverse | last post by:
Hey - I am making my first C# form application! (More a teach myself app than any pratical application) I have a listbox that always has the control so I made an event handler for KeyDown. I seem to be losing information when Casting to char, since I never have any problem using special keys if I use something like e.KeyCode == Keys.Delete But . . there is no Keys.Astericks (or Star or similar)
3
4303
by: win | last post by:
when the cursor is in a textbox, only coding in the keydown event of the textbox triggered, the coding in the keydown event of the form does not triggered! Problem: I need to change a VB6 program to .Net. It uses function key(e.g. F12) to close the form, now i need to write the coding in the keydown event of all controls form. Can anyone help me? Thanks a lot.
2
19297
by: Tony Johansson | last post by:
Hello! I have created a Control that consist of a label and a textbox.I have called this class ctlLabelTextbox. public partial class ctlLabelTextbox : UserControl { .... } The class that I have created for this purpose is derived from class UserControl.
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9023
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5552
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4100
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.