By the way , there were a few other errors :
the index start at 0, not 1
when you press the down key the listbox already go to next element so when you do that
you go to the second next element..Code:ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
the next element is selected after the end of the keydown event so you need
instead ofCode:TextBox1.Text = ListBox1.Items(ListBox1.SelectedIndex + 1).ToString
here is a correctionCode:TextBox1.Text = ListBox1.SelectedItem.ToString
Code:Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load ListBox1.Items.Add("Times New Roman") ListBox1.Items.Add("Arial") ListBox1.Items.Add("Arial Narrow") ListBox1.Items.Add("Monotype corsiva") ListBox1.Items.Add("Verdana") ListBox1.Items.Add("Andelip") ListBox1.Items.Add("Obit BT") ListBox1.Items.Add("LCD") ListBox1.Items.Add("Western") ListBox1.Items.Add("Roman") ListBox1.SelectedIndex = 0 TextBox1.Text = ListBox1.SelectedItem.ToString End Sub Private Sub listbox_KeyDown(sender As Object, e As KeyEventArgs) Handles ListBox1.KeyDown If e.KeyCode = Keys.Down Then If ListBox1.SelectedIndex < ListBox1.Items.Count Then TextBox1.Text = ListBox1.Items(ListBox1.SelectedIndex + 1).ToString End If End If If e.KeyCode = Keys.Up Then If ListBox1.SelectedIndex > 0 Then TextBox1.Text = ListBox1.Items(ListBox1.SelectedIndex - 1).ToString End If End If End Sub End Class





Reply With Quote
