Enter to go to the next TextBox????

Public Sub NextLine(ByVal ad As TextBox, ByVal da As Keys)

If da.KeyCode = Keys.Enter Then

ad.Focus()

End If

End Sub

I want to enter text in a textbox and when i hit enter i need it to go to the next textbox....Instead of writing a KeyDown event for all my textboxes i tried to write this function but it doesnt seem to work saying that option strict on dissallows late binding.....Any help I thought i would just be able to pass the value of the textbox that should recieve focus after ENTER is pressed....any help would be great.....




Answer this question

Enter to go to the next TextBox????

  • vincentvdb

    to stop the 'beep' try putting the e.Handled line last in the 'if' statement; might not work, but it works in the key press event
  • --JC--

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

    If e.KeyChar = Chr(13) Then

    System.Windows.Forms.SendKeys.Send("{Tab}")

    End If

    End Sub

    and set tab to 1 in first box

    and set tab to 2 in second box

    this might not be the best way but it works



  • jchmack12

    The focus event doesn't do what you think it does, you want the .Select() event.  You can have one event that you handle the key for all of your textboxes.  Try this;  create a form, put two textboxes on it then paste in this code:

    Private Sub Check_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown, TextBox2.KeyDown
        
    If e.KeyCode = Keys.Enter Then
             
    e.Handled = True
             
    Me.SelectNextControl(sender, True, True, True, True)
        
    End If
    End Sub

    I have yet to figure out how to keep the UI from beeping at the user when they press Enter though.


  • Chris Vega

    System.Data.SqlClient.SqlException: SQL Server does not exist or access denied.
    at System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransactio
    n)
    at System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConn
    ectionString options, Boolean& isInTransaction)
    at System.Data.SqlClient.SqlConnection.Open()
    at ConsoleApplication17.Class1.Main(String[] args) in c:\documents and settin
    gs\mr. powers\my documents\visual studio projects\consoleapplication17\class1.cs
    :line 23

    this is what i did to get this exception.....

    string connection = System.Configuration.ConfigurationSettings.AppSettings["connstring"];

    SqlConnection cn = new SqlConnection(connection);

    try

    {

    string quu = "SELECT * FROM Class";

    cn.Open();

    SqlCommand cmd = new SqlCommand(quu,cn);

    SqlDataReader dr;

    dr = cmd.ExecuteReader();

    }

    catch(Exception e)

    {

    Console.WriteLine(e.ToString());

    Console.ReadLine();

    }



  • Enter to go to the next TextBox????