0

hi
im trying to populate a datagrid view with the contents af a text file i used the following code:

 Private Sub Button15_Click(sender As System.Object, e As System.EventArgs) Handles Button15.Click
        Dim lines = (From line In IO.File.ReadAllLines(strPath) _'strPath is the location of text file
                          Select line.Split(CChar(vbTab))).ToArray

        For x As Integer = 0 To lines(0).GetUpperBound(0)
            dgQuotation.Columns.Add(lines(0)(x), lines(0)(x))
        Next
        For x As Integer = 1 To lines.GetUpperBound(0)
            dgQuotation.Rows.Add(lines(x))
        Next
    End Sub

but every time i run the program i get the following run time error:
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.
please help im new to vb so i dont know how to solve this one thanks in advance

2
Contributors
1
Reply
12
Views
3 Years
Discussion Span
Last Post by tinstaafl
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.