我有简单的代码:
Public Class Form1
Dim table As New DataTable
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DataGridView1.DataSource = table
TextBox1.Text = table.Rows.Count
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
table.Columns.Add()
TextBox1.Text = table.Rows.Count
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
table.Rows.Add()
TextBox1.Text = table.Rows.Count
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
table.Reset()
TextBox1.Text = table.Rows.Count
End Sub
End Class
加载表单后,我可以添加一些列和行,一切正常。我可以看到每个添加的列或行。在 table.reset() 之后我尝试添加一些行,但只能看到没有任何行的列标题。同时,文本框显示了适量的添加(不可见?)行。这是一个错误还是我只是忘记了什么?
谢谢。