[VB.NET]將集合類別繫結至DataGridView並使其具備新增功能
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lst As New List(Of Person)
lst.Add(New Person With {.Name = "Larry"})
DataGridView1.DataSource = lst
End Sub
End Class
Class Person Dim _name As String Property Name() As String Get Return _name End Get Set(ByVal value As String) _name = value End Set End Property End Class
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lst As New List(Of Person)
lst.Add(New Person With {.Name = "Larry"})
Dim binding As New BindingSource
binding.DataSource = lst
binding.AllowNew = True
DataGridView1.DataSource = Binding
End Sub
End Class