Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TAB Control Utility and More 1

Status
Not open for further replies.

daniellee4874

Programmer
Feb 27, 2007
11
US
I was wondering if anyone knew how to create a TAB control utility. For example:

If fields are:
No
Category
Price
Partner
Material

User should be able to define in the control client to “TAB” to a field that they specify. For example although the fields are:
No
Category
Price
Partner
Material

A user can define that on “TAB” they jump from the “NO” field to the “Partner” field, effectively bypassing the “Category” and “Price” fields.
____________________________________________________
Ideally I would to create to be able to do this:

User’s will be able to put fields in the order that is most important to them

For example fields currently are:
No
Category
Price
Partner
Material

But users can define them as:
No
Price
Partner
Category
Material

Let me know if anyone has ideas on how to do this.

 
Hello daniellee4874,

Drop the following code on your form and see if it does what you are looking to do:
Code:
' NOTE: Form KeyPreview property must be set to True in designer.

' Key = TextBox Name, Value = TextBox control.
Private m_TextBoxes As New Hashtable

Private Sub YourFormName_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.KeyPreview = True

    ' Create sorted list to use as source for combo box.
    Dim list As New SortedList
    For Each control As Forms.Control In Me.Controls
        If TypeOf control Is Forms.TextBox Then

            ' I prefix TextBoxes as txtTextBoxName.
            Dim name As String = control.Name.Substring(3)
            list.Add(name, Nothing)

            ' Save hash table of text boxes.
            m_TextBoxes.Add(name, control)
        End If
    Next

    ' Load text box name combo box with sorted list.
    Me.cboControls.DataSource = list.Keys
    ' Set combo box of text box names to selected index 0.
    Me.cboControls.SelectedIndex = 0
End Sub 'YourFormName_Load

Private Sub YourFormName_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
    ' Ignore Alt+Tab or Ctrl+Tab.
    If e.KeyCode = Keys.Tab AndAlso Not e.Alt AndAlso Not e.Control Then
        ' Focus to combo box selected item text box.
        If Me.cboControls.SelectedIndex <> -1 Then
            Dim name As String = Me.cboControls.SelectedItem
            If m_TextBoxes.Contains(name) Then
                ' Set focus to text box selected by user.
                DirectCast(m_TextBoxes.Item(name), TextBox).Focus()
                ' Eat the Tab key.
                e.Handled = True
            End If
        End If
    End If
End Sub 'FormKeyUp_KeyUp
Note that you need to set your form's KeyPreview property to True for this code to work.

My sample code above assumes 5 text boxes named txtNo, txtPrice, etc per your post. It also assumes a combo box named cboTextBoxes which will be loaded with the text box names from the form. When the user presses the tab key the focus will be given to the text box which the user has selected from the comob box. Good Luck!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top