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.

VB Code:
  1. Private Sub addTextBox()
  2.         Dim counter As Integer
  3.         counter += 1
  4.  
  5.         Dim ht As Integer = 0
  6.         For counter = 0 To lstTemplateFields.Items.Count - 1     '<------------ Listbox
  7.             lstTemplateFields.SelectedIndex = counter.ToString
  8.             Dim TextBox As New TextBox
  9.             Dim Label As New Label
  10.  
  11.             With Label
  12.                 Label.Name = "lblSearch " & counter + 1
  13.                 Label.Dock = DockStyle.Bottom
  14.                 Label.Text = lstTemplateFields.SelectedItem & ":"
  15.                 Me.Panel3.Controls.Add(Label)
  16.             End With
  17.  
  18.             With TextBox
  19.                 Label.Tag = counter
  20.                 TextBox.Anchor = AnchorStyles.Left Or AnchorStyles.Right
  21.                 TextBox.Name = "txtSearch " & counter + 1
  22.                 TextBox.Dock = DockStyle.Bottom
  23.                 Me.Panel3.Controls.Add(TextBox)
  24.  
  25.             End With
  26.  
  27.             '*****************************
  28.             'Add TextBox to the array
  29.             aTxtBoxes.Add(TextBox)
  30.  
  31.             ' Wire up event handler for the text box to the routine defined below.
  32.             AddHandler TextBox.TextChanged, AddressOf TextBox_EventHandler
  33.             '*****************************
  34.             ht += Label.Height
  35.             ht += TextBox.Height
  36.  
  37.         Next
  38.         Panel3.Height = ht
  39.  
  40.     End Sub
  41.    
  42.     Private Sub TextBox_EventHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
  43.         Dim i As Integer
  44.         Dim txtBox As TextBox = CType(sender, TextBox)
  45.  
  46.         'For i = 0 To lstSelection.Items.Count - 1
  47.         strSearch &= "{" & "[" & cboTemplate.SelectedItem & "]" & ":[" & _
  48.                  lstTemplateFields.Items(i) & "]" & "=" & txtBox.Text & "}" & "|"
  49.  
  50.         strSearch = strSearch.Substring(0, strSearch.Length - 1)
  51.  
  52.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  53.         MsgBox(strSearch)
  54.     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