title: How to set the Tab Index or current Active control from code in C#
body: <p>I have tried following method, but it didn't work at all, current focus stays on the very first textbox to whom i have set as TabIndex 0 through UI :-</p>
  
  <pre><code>private void OnFormLoad(object sender, EventArgs e)
          {
              txtServername.Text = Properties.Settings.Default.LastServerName;
              txtDatabase.Text = Properties.Settings.Default.LastDatabase;
              txtUsername.Text = Properties.Settings.Default.LastUserName;
              if (!String.IsNullOrWhiteSpace(txtServername.Text))
                  txtDatabase.SelectNextControl(ActiveControl, false, true, true, true);
              if (!String.IsNullOrWhiteSpace(txtDatabase.Text))
                  txtUsername.SelectNextControl(ActiveControl, false, true, true, true);
              if (!String.IsNullOrWhiteSpace(txtUsername.Text))
                  txtPassword.SelectNextControl(ActiveControl, false, true, true, true);
          }
  </code></pre>
  
  <p>Could someone please suggest a solution to above problem?</p>