try this:
vb Code:
Public Class Form1 ''' <summary> ''' Product Structure ''' </summary> ''' <remarks>contains a string member + a double member. ''' overriding the ToString, determines what is displayed in the listbox when you add a Product</remarks> Private Structure Product Dim itemNumber As String Dim price As Double Public Overrides Function ToString() As String Return Me.itemNumber End Function End Structure ''' <summary> ''' products array ''' </summary> ''' <remarks>5 element array of Product</remarks> Dim products(4) As Product ''' <summary> ''' Form1_Load event ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks>here we read the text file, then loop through the lines + load the products array + add products to listbox</remarks> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim lines() As String = IO.File.ReadAllLines("fileName.txt") Dim counter As Integer = 0 For x As Integer = 0 To lines.GetUpperBound(0) Step 2 products(counter).itemNumber = lines(x) products(counter).price = CDbl(lines(x + 1)) ListBox1.Items.Add(products(counter)) counter += 1 Next End Sub ''' <summary> ''' ListBox1_SelectedIndexChanged event ''' </summary> ''' <param name="sender"></param> ''' <param name="e"></param> ''' <remarks>this shows how you can use the ListBox.SelectedItem</remarks> Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged Label1.Text = DirectCast(ListBox1.SelectedItem, Product).price.ToString("c2") End Sub End Class




Reply With Quote