Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15722

Why can not select all text in textbox after focus to textbox ?

$
0
0
In then form there is TextBox and a ListBox. When I Press Down or Up Key I want to Select ListBox item. Then After Selected item comes into the TextBox and Then after I want to select all Text in TextBox. But I couldn't do it.

Where must I change into the code ?

Advanced Thanks.

Code:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.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 = 1
      TextBox1.Text = ListBox1.SelectedItem.ToString

  End Sub

  Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
      If e.KeyCode = Keys.Down Then
          If ListBox1.SelectedIndex <= ListBox1.Items.Count - 2 Then
              ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
              TextBox1.Text = ListBox1.SelectedItem.ToString

              ListBox1.Focus()
          End If
      End If

      If e.KeyCode = Keys.Up Then
          If ListBox1.SelectedIndex >= 1 Then
              ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
              TextBox1.Text = ListBox1.SelectedItem.ToString

              ListBox1.Focus()
          End If
      End If
  End Sub

  Private Sub ListBox1_GotFocus(sender As Object, e As EventArgs) Handles ListBox1.GotFocus
      TextBox1.SelectAll()
      TextBox1.Focus()
  End Sub


Viewing all articles
Browse latest Browse all 15722

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>