#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0

    How do you have the cursor advance to the next input field when the user hits <ENTER>


    How do you have the cursor advance to the next input field when the user hits <ENTER> in VB.NET

    I would appreicate any help. Thank you in advance..!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Brisbane, Australia
    Posts
    50
    Rep Power
    11
    Not so sure in VB.NET, I use C# more often. However, the concept should be same.

    This is how I would do it:
    I would write a KeyPressEventHandler to handle the controls (input fields) which need to have the "Enter" key as the tab key.

    Code:
    Control_KeyPress(object sender, KeyPressEventHandler e){
      if(e.KeyChar!=Keys.Enter){
        return; //skip all keys except Enter
      }
    
        //for tab index sorting
      int currentIndex = ((Control)sender).TabIndex;
      int nextIndex = 5000; // for tab index sorting
    
      Control controlToFocus = null;
      foreach(Control c in this.Controls){
        if((c.TabIndex<nextIndex)&&c.TabIndex>currentIndex)){
          if(c.TabStop){
            nextIndex = c.TabIndex;
            controlToFocus = c;
          }
        }
      }
    
      if(controlToFocus !=null){
        controlToFocus.Focus();
      }
    }

    hope it helps

IMN logo majestic logo threadwatch logo seochat tools logo