Results 1 to 3 of 3

Thread: Using an Array with a textbox

  1. #1

    Thread Starter
    New Member jlwesq's Avatar
    Join Date
    Oct 2011
    Location
    SoCal
    Posts
    2

    Using an Array with a textbox

    I'm trying to use a textbox to locate a specific product. It partially works (ie, it doesn't crash) but what I am trying to do is get the textbox to autoload the description as the user types. I have several products of similar description and the user needs to see the entire description in order to make a selection. Any help greatly appreciated.

    Code:
    Public Class Form1
    
        Dim ContractorsName As Contractors
        Dim JobName As Job_Name
        Dim JobAddress As Job_Name
        Dim InventoryProduct(25) As Products
    
        Dim IndexInteger As Integer = 0
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            InventoryProduct(0).Description = "Stud 2X4X8' "
            InventoryProduct(0).PriceEach = "1.75"
            InventoryProduct(1).Description = " Stud 2X4X10'"
            InventoryProduct(1).PriceEach = "2.35"
            InventoryProduct(2).Description = "Post 4X4X8' "
            InventoryProduct(2).PriceEach = "6.35"
            InventoryProduct(3).Description = "Post 4X4X10'"
            InventoryProduct(3).PriceEach = "7.25"
            InventoryProduct(4).Description = "Post 4X4X14'"
            InventoryProduct(4).PriceEach = "7.95"
            InventoryProduct(5).Description = "Board 1X6X8' "
            InventoryProduct(5).PriceEach = "8.90"
            InventoryProduct(6).Description = "Board 1X6X12' "
            InventoryProduct(6).PriceEach = "9.25"
            InventoryProduct(7).Description = "Board 1X6X18' "
            InventoryProduct(7).PriceEach = "15.50"
            InventoryProduct(8).Description = "Board 2X8X8' "
            InventoryProduct(8).PriceEach = "11.42"
            InventoryProduct(9).Description = "Post 2X8X14' "
            InventoryProduct(9).PriceEach = "9.95"
            InventoryProduct(10).Description = "Nail 8D 5#"
            InventoryProduct(10).PriceEach = "16.81"
            InventoryProduct(11).Description = "Nail 8D 5000 Strip"
            InventoryProduct(11).PriceEach = "89.95"
            InventoryProduct(12).Description = "Nail 10D 5#"
            InventoryProduct(12).PriceEach = "16.81"
            InventoryProduct(13).Description = "Nail 10D 5000 Strip"
            InventoryProduct(13).PriceEach = "89.95"
            InventoryProduct(14).Description = "Nail 16D 5#"
            InventoryProduct(14).PriceEach = "16.81"
            InventoryProduct(15).Description = "Nail 16D 5000 Strip"
            InventoryProduct(15).PriceEach = "89.95"
            InventoryProduct(16).Description = "Nail Roofing  #11X1 1/2 5#"
            InventoryProduct(16).PriceEach = "10.47"
            InventoryProduct(17).Description = "Nail Roofing Grip Rite #11X 1 1/2 5#"
            InventoryProduct(17).PriceEach = "33.50"
            InventoryProduct(18).Description = "Nail Roofing #11X1 3/4 5#"
            InventoryProduct(18).PriceEach = "6.89"
            InventoryProduct(19).Description = "Nail Roofing #12X1 5#"
            InventoryProduct(19).PriceEach = "8.75"
            InventoryProduct(20).Description = "Plywood Sheathing 4'X8'X15/32 "
            InventoryProduct(20).PriceEach = "14.77"
            InventoryProduct(21).Description = "Plywood Sheathing 4'X8'X19/32"
            InventoryProduct(21).PriceEach = "18.59"
            InventoryProduct(22).Description = "Plywood Sheathing 4'X8'X23/32  Press. Treat."
            InventoryProduct(22).PriceEach = "43.97"
            InventoryProduct(23).Description = "Floor Board 4'X8'X23/32 T&G "
            InventoryProduct(23).PriceEach = "23.57"
            InventoryProduct(24).Description = "Sheetrock 4'X8'X1/2 "
            InventoryProduct(24).PriceEach = "9.38"
    
        End Sub
    
        Private Sub AddButton_Click(sender As System.Object, e As System.EventArgs) Handles AddButton.Click
            ProductTextBox.Text = InventoryProduct(IndexInteger).Description
            PriceLabel.Text = InventoryProduct(IndexInteger).PriceEach
        End Sub
    
        Private Sub DescTextBox_TextChanged(sender As System.Object, e As System.EventArgs) Handles DescTextBox.TextChanged
            Dim Found As Boolean = False
            Dim TableCompareString As String
            Dim TextCompareString As String
    
            Do While Not Found And IndexInteger < 25
    
                TableCompareString = InventoryProduct(IndexInteger).Description.ToString().ToUpper()
                TextCompareString = DescTextBox.Text.ToUpper()
    
                If TableCompareString.StartsWith(TextCompareString) Then
    
                    Found = True
    
                Else
                    IndexInteger += 1
                    IndexLabel.Text = IndexInteger
                End If
    
            Loop
        End Sub
    End Class

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Using an Array with a textbox

    I would suggest that you use the auto-complete functionality already built into the TextBox control. Take a look at the properties whose names begin with "AutoComplete". Read the documentation for those properties and search online for examples if required. If you still have issues, post back and show us what you've done and let us know where the problem is.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member jlwesq's Avatar
    Join Date
    Oct 2011
    Location
    SoCal
    Posts
    2

    Re: Using an Array with a textbox

    It work just the way I want. Only problem is now when I exit the program it throws and exception.

    {"Cannot bind to the property or column ZIP Code on the DataSource.
    Parameter name: dataMember"}

    I simply can't resolve this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width