Click here to Skip to main content
15,072,046 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I'm completely new to VB.net and have been given a homework assignment. I need to be able to read certain lines and display them in a DateGridView. I have been able to link my notepad .txt file to the DGV however it reads the whole file as opposed to the specific line. I have 4 buttons: btn1, btn2, btn3, btn4. I want each button to show the respective lines in the text file. After researching on-line for the past week I'm still stuck. If anyone could help me I would really appreciate it.

Text File ("database.txt")
c1 c2 c3
one 1-1 1-2
two 2-2 2-3
three 3-2 3-3
four 4-2 4-3


VB
Public Class Form1

    Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click

        Dim lines = (From line In IO.File.ReadAllLines("database.txt") _
                    Select line.Split(CChar(vbTab))).ToArray
        For x As Integer = 0 To lines(0).GetUpperBound(0)
            DataGridView1.Columns.Add(lines(0)(x), lines(0)(x))
        Next
        For x As Integer = 1 To lines.GetUpperBound(0)
            DataGridView1.Rows.Add(lines(x))
        Next
    End Sub


End Class
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900