automatically highlight next item in listbox

VBnetster

Active member
Joined
Feb 15, 2008
Messages
32
Programming Experience
Beginner
hihi

Im learning how to use the listbox control.. its pretty cool.

I have code to delete a selected item from a listbox when the keyboards delete key is pressed. but after the item is deleted i would like to automatically select the next item in the listbox instead of it losing focus.

I've tried a few times but cant get it right.. need a little help on this one.

thanks
 
Look into using the SelectedIndex method, you can both get and set this.
 
eh just used SendKeys.Send("{Down}") this works fine :) thanks anyway..

it's always after posting that i fix the problem... :rolleyes:

edit:

actually you were kinda right... this is better than the sendkeys:

If e.KeyCode = Keys.Delete Then
Dim sindex As Integer = ListBox1.Items.IndexOf(ListBox1.SelectedItem)
ListBox1.Items.Remove(ListBox1.SelectedItem)
ListBox1.SetSelected(sindex, True)
End If

i was so close so many times! argh!
 
Last edited:
Back
Top