Hi
I have a ListBox Control containing 5 items. This control displays the current condition and allows the condition to change. The ListBox.SelectedIndex is calculated from the current condition (normally item 2 in the list) and displayed. If the user requires to change this condition the Keyboard Up/Down would be used for navigation (The App is very keyboard intensive), however if the ListBox.SelectedIndex is set at 2 and the keyboard down arrow is pressed the selected item displayed changes to 0 not 3 as required. Is there a way to synchronise the keyboard control with the current selected index?
Not sure if it makes a difference but the App is WPF
Thanks in Advance
ListBox and Keyboard ControlProblem with SelectedIndex & Keyboard Relationship
Page 1 of 1
3 Replies - 2902 Views - Last Post: 29 March 2009 - 06:51 AM
Replies To: ListBox and Keyboard Control
#2
Re: ListBox and Keyboard Control
Posted 27 March 2009 - 06:07 AM
if we have some code, we may be able to help you with the error!
please paste some code within [code] Code here! [/code] brackets
I am not sure what methods you are using to do the keyboard control, but I would have something like...
(you would of course have to check if you are at the end of the list etc..) this is just to give an idea.
please paste some code within [code] Code here! [/code] brackets
I am not sure what methods you are using to do the keyboard control, but I would have something like...
on key_down ListBox.SelectedIndex = Listbox.SelectedIndex + 1
(you would of course have to check if you are at the end of the list etc..) this is just to give an idea.
This post has been edited by krum110487: 27 March 2009 - 06:12 AM
#3
Re: ListBox and Keyboard Control
Posted 27 March 2009 - 04:46 PM
Many thanks for pointing me to the obvious. This is really a case of "not seeing the wood for the trees" and my stupidity. The reason no code was pasted was that the only code I had was the ListBox.Selectedndex. Having tested the app and discovered that the keyboard responded, although incorrectly, I had assumed that my problem was deep and buried in either .Net or the OS. It had not occurred to me that the keyboard still needed handling. Here is the code I have arrived at and the control now functions as expected:
Again many thanks!
Private Sub lstFps_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles lstFps.PreviewKeyDown Dim intN As Integer Dim intCount As Integer = lstFps.Items.Count Select Case e.Key Case Key.Down intN = lstFps.SelectedIndex + 1 If intN = intCount Then lstFps.SelectedIndex = 0 Else lstFps.SelectedIndex = intN End If e.Handled = True Case Key.Up intN = lstFps.SelectedIndex - 1 If intN < 0 Then lstFps.SelectedIndex = intCount - 1 Else lstFps.SelectedIndex = intN End If e.Handled = True Case Key.Enter txtTcInput.Focus() End Select End Sub
Again many thanks!
#4
Re: ListBox and Keyboard Control
Posted 29 March 2009 - 06:51 AM
Hi,
Good afternoon,
I want to ask how to write a code to sort the Items I add to the listbox from the Input box in vb.net 2005
Please help me I have an exam and I want to know how to write it?
thanks,
Bu Khaled
Good afternoon,
I want to ask how to write a code to sort the Items I add to the listbox from the Input box in vb.net 2005
Please help me I have an exam and I want to know how to write it?
thanks,
Bu Khaled
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|