.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Resource Bookmark and Share   

How to show text files records in a listview

Posted By:satyapriyanayak       Posted Date: August 30, 2013    Points: 40    Category:    URL: http://www.dotnetspark.com  

We will know how to show text files records in a listview

Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Id As String
        Dim Name As String
        Dim Gender As String
        Dim Address As String


            Dim sr As StreamReader
            Dim fs As FileStream
            fs = New FileStream(("C:\temp\a.txt"), FileMode.OpenOrCreate)
            sr = New StreamReader(fs)
            Dim itm As Object
            itm = sr.ReadLine
            While Not itm = Nothing
                Dim split As String() = itm.Split(New [Char]() {" "})
                Id = split(0)
                Name = split(1)
                Gender = split(2)
                Address = split(3)
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Name)
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Gender)
                ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(Address)
                itm = sr.ReadLine
            End While

            ListView1.Columns.Add("Id", 70, HorizontalAlignment.Center)
            ListView1.Columns.Add("Name", 70, HorizontalAlignment.Center)
            ListView1.Columns.Add("Gender", 70, HorizontalAlignment.Center)
            ListView1.Columns.Add("Address", 70, HorizontalAlignment.Center)
            ListView1.View = View.Details
            ListView1.GridLines = True
            ListView1.BackColor = Color.Aqua
            ListView1.ForeColor = Color.Blue
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message, "Load Tool Data Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
End Class


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend