Results 1 to 4 of 4

Thread: Tab pages reading txt to list box ?

Threaded View

  1. #1

    Thread Starter
    Lively Member polecat's Avatar
    Join Date
    Jul 2005
    Location
    Wolverhampton
    Posts
    83

    Resolved Tab pages reading txt to list box ?

    Hi forgive me im still new to vb.net and progging!! I have my app using tabpages thought it was easier for my project,
    on tab 1 i have 2 text boxes with and output from other text boxes
    I have a button to save to file this works great with snippets from you guys on here .

    Now on tab2 i have a listbox the list box is populated from the saved text file works ok apart from the saved items from tab1 dont appear till the program is next run? I have hidden button3 as i have put the TabControl1.Enter there to trigger the button action as i wanted the list to load on clicking the tab not a button if you know what i mean?
    The code im using is below if any body can help with away of it kind refreshing the file before populating thre list?

    VB Code:
    1. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click, TabControl1.Enter
    2.  
    3.         ' Load the ListBox from a file.
    4.         Try
    5.  
    6.             Dim file_name As String = DataFile()
    7.             Dim stream_reader As New IO.StreamReader(Application.StartupPath & "\mysaved.txt")
    8.  
    9.             ListBox1.Items.AddRange(Split(stream_reader.ReadToEnd, _
    10.                 vbCrLf))
    11.             ListBox1.SelectedIndex = 0
    12.             stream_reader.Close()
    13.         Catch exc As Exception
    14.             ' Report all errors.
    15.             MsgBox(exc.Message, MsgBoxStyle.Exclamation, "Read " & _
    16.                 "Error")
    17.         End Try
    18.  
    19.     End Sub
    20.  
    21.     ' Return the data file name.
    22.     Private Function DataFile() As String
    23.         Dim file_name As String = Application.StartupPath
    24.  
    25.         If file_name.EndsWith("\bin") Then file_name = _
    26.             file_name.Remove(file_name.Length - 4, 4)
    27.         file_name &= "\mysaved.txt"
    28.         Return file_name
    29.     End Function
    Last edited by polecat; May 22nd, 2006 at 03:16 PM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width