private void FocusFirstTabIndex(Control container) { // init search result varialble Control searchResult = null; // find the control with the lowest tab index foreach (Control control in container.Controls) { if (control.CanFocus && (searchResult == null || control.TabIndex < searchResult.TabIndex)) { searchResult = control; } } // check if anything searchResult if (searchResult != null) { // focus found control searchResult.Focus(); } else { // focus the container container.Focus(); } }