By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,529 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,529 IT Pros & Developers. It's quick & easy.

List box problem

100+
P: 121
Hi
i have a text box and a list box. I have a table with a list of names in the database
now when i write a letter(for eg A) in text bo all names starting with A will be displayed in the list box .this works with me if there are more names i hav to use
mouse to navigate in the listbox. where as keydown event of list box des not work.ls can yoygive me the solution.
thanks in advance
Jan 7 '08 #1
Share this Question
Share on Google+
16 Replies


debasisdas
Expert 5K+
P: 8,127
What are you trying to do in the Keydown event of the listbox ?
Jan 7 '08 #2

100+
P: 121
What are you trying to do in the Keydown event of the listbox ?
i want to navigate up an d down in list box using arrow keys without using mouse
Jan 7 '08 #3

Expert 5K+
P: 8,434
i want to navigate up an d down in list box using arrow keys without using mouse
As long as the listbox has the focus, that should work shouldn't it?

By the way, what version of VB is this?
Jan 7 '08 #4

100+
P: 121
As long as the listbox has the focus, that should work shouldn't it?

By the way, what version of VB is this?
when i us only list box it woks
but when use quer to insert data in the list box it does not work
use vb6
Jan 7 '08 #5

debasisdas
Expert 5K+
P: 8,127
when i us only list box it woks
but when use quer to insert data in the list box it does not work
use vb6
i am not sure what exactly is your problem.
Jan 7 '08 #6

QVeen72
Expert 100+
P: 1,445
i want to navigate up an d down in list box using arrow keys without using mouse
Hi,

Set the Properties of listbox : Sorted = True

Regards
Veena
Jan 7 '08 #7

100+
P: 121
Hi
i want to design form in the same way as when we have alist of address stored
when we want to compose if we write one letter on textbox which will display a list box with starting letter as of text box.now for selecting names in the list box can be navigated with arrow keys instead of mouse.in the same i designed in vb i get the names in the list box with the starting letter as specified in the text box
but i am not able to move up and down thrugh arrow keys instead i have to use mouse
please help
i also set sort properties to true
Jan 7 '08 #8

QVeen72
Expert 100+
P: 1,445
Hi,

Arrow Keys in List Box will work only if ListBox has the Focus. Set focus to ListBox.
Moreover Check if your Arrow Keys are working properly or not. Sounds silly but sometimes it happens.. NumLock will be On and people complain their Arrow Keys on the Number pad does not work..

Is there any Code you have written in in KeyPress/KeyUp/KeyDown event of the ListBox. If any code is there then, you have to keep a breakpoint and check..

Regards
Veena
Jan 7 '08 #9

debasisdas
Expert 5K+
P: 8,127
Please do not start duplicate thread for the same question.

Both the threads are merged for better management of the forum
Jan 7 '08 #10

100+
P: 121
Please do not start duplicate thread for the same question.

Both the threads are merged for better management of the forum
if i use list1.setfocus.it will focus only on first element
Jan 7 '08 #11

debasisdas
Expert 5K+
P: 8,127
if i use list1.setfocus.it will focus only on first element
after that you need to use the keyboard to move up and down the list.
Jan 7 '08 #12

Ali Rizwan
100+
P: 927
if i use list1.setfocus.it will focus only on first element
Write this code under form key down event.

Expand|Select|Wrap|Line Numbers
  1. If Key = VbKeyDown Then List1.Listindex = List1.Listindex - 1
  2. If Key = VbKeyUp Then List1.Listindex = List1.Listindex + 1
Regards

>> ALI <<
Jan 7 '08 #13

Expert 5K+
P: 8,434
Write this code under form key down event...
You might be better advised to do that in the event procedure for the textbox, rather than the form. And of course, you might want to check the value of ListIndex before changing it.

Not sure how much that matters - maybe someone can tell me, does it adjust or crash if you go past the end of the list?
Jan 8 '08 #14

Ali Rizwan
100+
P: 927
You might be better advised to do that in the event procedure for the textbox, rather than the form. And of course, you might want to check the value of ListIndex before changing it.

Not sure how much that matters - maybe someone can tell me, does it adjust or crash if you go past the end of the list?
Yes Killer, I checked this thing and found that when its the end of list an error occur.
I have used if statement and also use error control but error remains.

Tell me also the solution for it.

Regards
>> ALI <<
Jan 8 '08 #15

QVeen72
Expert 100+
P: 1,445
Yes Killer, I checked this thing and found that when its the end of list an error occur.
I have used if statement and also use error control but error remains.

Tell me also the solution for it.

Regards
>> ALI <<
Hi Ali,

Change your code to :

Expand|Select|Wrap|Line Numbers
  1. If Key = VbKeyDown And List1.ListIndex > 0 Then 
  2.     List1.Listindex = List1.Listindex - 1
  3. End If
  4. If Key = VbKeyUp And List1.ListIndex < List1.ListCount-1 Then 
  5.     List1.Listindex = List1.Listindex + 1
  6. End If
  7.  
  8.  
REgards
Veena
Jan 8 '08 #16

Expert 5K+
P: 8,434
I have used if statement and also use error control but error remains.
Well, without the details it's hard to be sure. But my first guess would be that you've assumed ListIndex would be between 1 and ListCount. In fact, it can range from 0 to (ListCount - 1).
Jan 9 '08 #17

Post your reply

Sign in to post your reply or Sign up for a free account.