我試圖填充DataGrid視圖與內容自動對焦,我用下面的代碼的文本文件:行不能以編程方式添加
Private Sub Button15_Click(sender As Object, e As EventArgs) _
Handles Button15.Click
'strPath is the location of text file
Dim lines = (From line In IO.File.ReadAllLines(strPath)
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
但我每次運行該程序,我得到以下運行時間時間錯誤:
Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound.
請幫忙,我是VB新手。提前致謝。
您必須在datagrid視圖的數據源中添加新行。 – Jade