I rarely deal with arrays.. Especially in vb.net where it's got arraylist.. so unless someone has a better solution heres what i did:
I couldnt find a way to remove an item from an array, unless i missed something.. So instead i split it (omitting the one to delete), then put it back together.
note this was not tested.. It's almost 4AM here & i'm only up because i'm trying to finish a system so I can get a few bucks..
Code:
Private Sub deleteStockItem(ByVal itemIndex As Integer)
Dim frontOfArray(1000) As Array
Dim endOfArray(1000) As Array
ReDim frontOfArray(itemIndex)
ReDim endOfArray(stockArray.Count - (itemIndex + 1))
Array.ConstrainedCopy(stockArray, 0, frontOfArray, 0, itemIndex)
Array.ConstrainedCopy(stockArray, itemIndex + 1, endOfArray, 0, endOfArray.Count)
Array.Clear(stockArray, 0, stockArray.Count)
Array.Copy(frontOfArray, stockArray, frontOfArray.Count)
stockArray.Concat(endOfArray)
End Sub
Here i used the same method as before to get the index number, but now i gave him a permanent accessable home:
Code:
private Function getItemArrayIndex(ByVal itemName As String) As Integer
For arrayIndex As Integer = 0 To (stockArray.Count - 1) Step 1
If IsNothing(stockArray(arrayIndex)) Then Return -1
If itemName = stockArray(arrayIndex)(0) Then
Return arrayIndex
End If
Next
Return -1
End Function
So we have a way to get the index number, so lets preserve some code space and put it to use:
Code:
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim listBox1Item As String = ListBox1.SelectedItem
Dim itemIndex As Integer = getItemArrayIndex(listBox1Item)
If listBox1Item = stockArray(itemIndex)(0) Then
txtName.Text = stockArray(itemIndex)(0)
txttype.Text = stockArray(itemIndex)(1)
txtprice.Text = stockArray(itemIndex)(3)
txtlocation.Text = stockArray(itemIndex)(4)
txtquantity.Text = stockArray(itemIndex)(2)
txtneeded.Text = stockArray(itemIndex)(5)
txttags.Text = stockArray(itemIndex)(8)
txtdescription.Text = stockArray(itemIndex)(9)
Exit Sub
End If
End Sub
If any issues i'll look at it tomorrow.. i'm done! lmao