我有这样的情况:
我有一些对象的列表或数组(尚未决定哪一个更适合我的目的,但这无关紧要)(例如人员列表)。在我的表单中,有一个DataGridView,我想在其中查看所有人及其属性。Persons属性可以在运行时编辑,我希望在DataGridView中立即看到这些更改。我用过
BindingSource
为此:
Dim _persons As New List(Of Person)
Dim persons As BindingSource = New BindingSource()
persons.DataSource = _persons
myGridView.DataSource = persons
现在,当我通过BindingSource(persons)添加/删除一个人时,这非常有效。这种变化我能立即看到。但如果我想编辑一个人呢?让我们上课:
Public Class Person
Public Property FirstName As Integer
Public Property SecondName As String
Public Property Address As String
End Class
如果我想编辑名字,我可以这样做:
_persons(1).FirstName = "John"
但这是直接通过列表而不是通过BindingSource进行的,因此此更改不会在DataGridView中产生影响。有没有办法通过BindingSource来实现这一点,从而影响DataGridView中的编辑?
很抱歉,这是我第一次使用BindingSource,所以这可能是一个愚蠢的问题。谢谢你们。