Knowing how to read a text file in Listbox is essential part in Visual Basic 2017 programming.
In this post I will teach you how to do it by using OpenFileDialog.
First let create a text file with notepad with the following data.
Now save the file somewhere on the local disk. I save it as a test file.txt on the Desktop.
Add a button in the form and title it Read text file; add a listbox too.
Above Public Class Form1 insert the following code
Imports System.IO
If you are complete beginner and you don't know how it looks like see on the picture bellow!
In the button insert the following code to read the text file in Listbox.
Dim OpenFileDialog1 As New OpenFileDialog
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim lines = File.ReadAllLines(OpenFileDialog1.FileName)
ListBox1.Items.Clear()
ListBox1.Items.AddRange(lines)
End If
Friday, October 27, 2017
How to read a text file in Listbox opened with OpenFileDialog
Tags
# ListBox
About Gabriel
Templatesyard is a blogger resources site is a provider of high quality blogger template with premium looking layout and robust design. The main mission of templatesyard is to provide the best quality blogger templates which are professionally designed and perfectlly seo optimized to deliver best result for your blog.
ListBox
Labels:
ListBox
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment