I have this situation:
I have a List or an Array (haven´t deciced which one is better for my purpose, but it doesn´t matter) of some objects (for example list of Persons). In my form there is a DataGridView where I want to see all persons and their attributes. Person´s attributes can be edited at a runtime and I want to see these changes immediatelly in DataGridView. I have used BindingSource
for this:
Dim _persons As New List(Of Person)
Dim persons As BindingSource = New BindingSource()
persons.DataSource = _persons
myGridView.DataSource = persons
Now when I add/remove a person via BindingSource (persons) this works perfectly. This change I can see immediatelly. But what if I want to edit one person? Lets have this class:
Public Class Person
Public Property FirstName As Integer
Public Property SecondName As String
Public Property Address As String
End Class
If I want to edit firstname I can do it this way:
_persons(1).FirstName = "John"
But this is directly via list and not via BindingSource so this change will not take affect in the DataGridView. Is there a way how to do that via BindingSource to take affect this edit in DataGridView?
I am sorry but this is first time I working with BindingSource so this is maybe a stupid question. Thank you guys.
You should affect the BindingSource
directly (not the List
you used to create the BindingSource), that is:
DirectCast(persons(1), Person).FirstName = "John"