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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Processing Textboxes @ run-time

Status
Not open for further replies.

Trancedified

Programmer
Joined
Apr 28, 2004
Messages
6
Location
US
Hello,

I have this code to create textboxes @ run-time based on however many database fields are loaded into a listbox, then one event handler to supposedly handle all the run-time textboxes.

I am using a special database program where I can search using a string like this:

{[mytemplate]:[field name1]=}|{[mytemplate]:[field name2]=}

I am hoping to build this string as the user types in the runtime textboxes.

So that if the user types a search criteria in [field name1], it will look like [field name1]=Johnson and the same for all the other fields.

Code:
        Private Sub addTextBox()
        Dim counter As Integer
        counter += 1

        Dim ht As Integer = 0
        For counter = 0 To lstTemplateFields.Items.Count - 1     '<------------ Listbox
            lstTemplateFields.SelectedIndex = counter.ToString
            Dim TextBox As New TextBox
            Dim Label As New Label

            With Label
                Label.Name = "lblSearch " & counter + 1
                Label.Dock = DockStyle.Bottom
                Label.Text = lstTemplateFields.SelectedItem & ":"
                Me.Panel3.Controls.Add(Label)
            End With

            With TextBox
                Label.Tag = counter
                TextBox.Anchor = AnchorStyles.Left Or AnchorStyles.Right
                TextBox.Name = "txtSearch " & counter + 1
                TextBox.Dock = DockStyle.Bottom
                Me.Panel3.Controls.Add(TextBox)

            End With

            '*****************************
            'Add TextBox to the array
            aTxtBoxes.Add(TextBox)

            ' Wire up event handler for the text box to the routine defined below.
            AddHandler TextBox.TextChanged, AddressOf TextBox_EventHandler
            '*****************************
            ht += Label.Height
            ht += TextBox.Height

        Next
        Panel3.Height = ht

    End Sub
   
    Private Sub TextBox_EventHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim i As Integer
        Dim txtBox As TextBox = CType(sender, TextBox)

        'For i = 0 To lstSelection.Items.Count - 1
        strSearch &= "{" & "[" & cboTemplate.SelectedItem & "]" & ":[" & _
                 lstTemplateFields.Items(i) & "]" & "=" & txtBox.Text & "}" & "|"

        strSearch = strSearch.Substring(0, strSearch.Length - 1)

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        MsgBox(strSearch)
    End Sub

If i were to click button 1, after typing with two shown textboxes the phrase, "as" the msgbox will show some bizzare results:

{[mytemplate]:[field name1]=a}|{[mytemplate]:[field name1]=a}|{[mytemplate]:[field name2]=a}|{[mytemplate]:[field name2]=a}|{[mytemplate]:[field name1]=as}|{[mytemplate]:[field name1]=as}|{[mytemplate]:[field name2]=as}|{[mytemplate]:[field name2]=as}

Example: I'm hoping if i type something in the first textbox it will be intelligent to know where to put the user's text into the search string and the same for the 1st textbox, 3rd, etc.

Any ideas? Thanks for your insight!

Chris





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top