Quote Originally Posted by elielCT View Post
I tried to explain this before...

Change the event handler for your textboxes
Code:
.TextChanged
to
Code:
.LostFocus

LostFocus is a far better idea. Requires less hacks and is very easy to implement given you don't have time for a rewrite.

So, with your code from post#67:

First, remove TextBox2 through TextBox10 from the designer and remove all references to them from the User form code. Also remove all the .Hide and .Show code.

Next, you have an error in your ListBox1_SelectedIndexChanged sub. You have the End If in the wrong place. It should be where you have the commented out End If. Also, get rid of the Exit Sub.
vb.net Code:
  1. Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
  2.     If ListBox1.SelectedIndex > -1 Then
  3.         Dim stock As String() = stockArray.First(Function(objArr) objArr(0) = ListBox1.SelectedItem.ToString)
  4.         For i As Integer = 0 To stock.Length - 1
  5.             Me.Controls("Txt" & (i + 1).ToString).Text = stock(i)
  6.         Next
  7.  
  8.         Dim listBox1Item As String = ListBox1.SelectedItem
  9.         Dim itemIndex As Integer = getItemArrayIndex(listBox1Item)
  10.    
  11.         txtreorderamount.Text = IIf(stockArray(itemIndex)(5) - stockArray(itemIndex)(2) < 0, 0, (stockArray(itemIndex)(5) - stockArray(itemIndex)(2)))
  12.         If stockArray(itemIndex)(6).ToString.ToLower.Contains("dangerous") Then
  13.             panalerts.BackColor = Color.Red
  14.             lblAlerts.Text = "Dangerous"
  15.         Else
  16.             panalerts.BackColor = Color.Green
  17.             lblAlerts.Text = "Safe"
  18.         End If
  19.  
  20.     End If
  21.  
  22. End Sub

For textboxes txt2 through txt8 and txtreorderamount, switch from handling the TextChanged event to handling the LostFocus event as suggested by elielCT, e.g.
vb.net Code:
  1. Private Sub txt2_LostFocus(sender As System.Object, e As System.EventArgs) Handles txt2.LostFocus
  2.     Dim listBox1Item As String = ListBox1.SelectedItem
  3.     Dim itemIndex As Integer = getItemArrayIndex(listBox1Item)
  4.     stockArray(itemIndex)(1) = txt2.Text
  5. End Sub

Similarly for txt1 textbox (the Name textbox), but also rewrite the value to the ListBox, otherwise the stock array and the listbox will be out of synch, your code will no longer find the listbox item in the (updated) stock array, and you'll get the errors you have been seeing:

vb.net Code:
  1. Private Sub txt1_LostFocus(sender As System.Object, e As System.EventArgs) Handles txt1.LostFocus
  2.     Dim listBox1Item As String = ListBox1.SelectedItem
  3.     Dim itemIndex As Integer = getItemArrayIndex(listBox1Item)
  4.     stockArray(itemIndex)(0) = txt1.Text
  5.  
  6.     ListBox1.Items(ListBox1.SelectedIndex) = txt1.Text
  7.  
  8. End Sub

There is lots of room for improvement (depending on how much time you have left) such as the use of buttons to update the array from the values in the textboxes as mentioned by both elielCT and AceInfinity.

You could reduce the amount of repeated code if you so wished, and also give your subs decent names (e.g. NameText_LostFocus instead of txt1_LostFocus and btnAppFilter_Click instead of Button1_Click). Start all your sub and function names with a capital letter (Pascal casing) or at least be consistent.

A few minor observations:
You don't close and dispose the StreamReader object in sub readFile (you could use a Using reader As... End Using block instead of the Dim, and then you don't need to worry about the closing/disposing of the StreamReader).

You should clear the textboxes, the restock label and the alerts label just after the call to ListBox1.Items.Clear() in your Search sub . At the moment, filtering repopulates the listbox, doesn't select an item in it, but leaves the textboxes populated from any previously selected listbox item.

Two of your labels display "Null" when the app is first started.

Clicking the "Apply" button while the search textbox still contains "Touch Here To Search" gave an unexpected result. You could disable the button until that message has been removed.