[Solved] VB.Net How do I store lines in a textbox as a variable for later use? [closed]


You should never use a control to store data. What you should be doing is have an “Cart” object which is a list of item orders. An item order should be an object which contains the order code, the quantity, and MAYBE the product description.

Private Class Product
    Property ProductCode As Integer
    Property Description As String
    Property StockQuantity As Integer
    Property Price As Decimal
End Class

Dim products As New List(Of Product)

Private Class OrderItem
    Public Property ProductCode As Integer
    Public Property Quantity As Integer
End Class

Dim cart As New List(Of OrderItem)

And in your combo box, you should bind it to the product list using Description as the .DisplayMember

When you click the “Add to Cart” button, you can then use the ComboBox.SelectedItem which will be the actual product object and add that directly to your cart.

At this point, instead of your data being stored in the RichTextBox, it is stored in a Cart object as a list of order items. You can use this list to populate your RichTextBox something like this.

Private Sub RefreshRtbOrders()
    RtbOrders.SuspendLayout()
    RtbOrders.Clear()
    For Each item As OrderItem In cart
        RtbOrders.AppendText(item.Quantity.ToString("0000  ") & products.Find(Function(x) x.ProductCode = item.ProductCode).Description & vbCrLf)
    Next
    CboProducts.ResumeLayout()
End Sub

You can then use the Cart object to update your database.

1

solved VB.Net How do I store lines in a textbox as a variable for later use? [closed]