[RESOLVED] [2005] BindingDataSource Add & Remove
I have created a DataSource Object that refers to a class I have created, this DataSource is binded to a DataGridView Control to display the contents of the class which works perfectly.
I am trying to add and remove items from the DataGridView dynamically, but should I do it by removing or adding the item from/to the class or the BindingDataSource?
VB Code:
Dim Accts As New AccountsCollection()
AccountCollectionBindingSource.AddNew(New Account("A","B"))
AccountCollectionBindingSource.RemoveAt(1)
' Or
Accts.Add(New Account("A","B"))
Accts.RemoveAt(1)
Both these methods work to adding or removing an item from the class object but which method is prefered or doesn't it matter?
The second part of my question is how do I get the DataGridView to reflect the changes?
VB Code:
' Now reset the datasource to reflect the changes?
AccountCollectionBindingSource.DataSource = Accts
The changes never are reflected until I restart the application.
Re: [2005] BindingDataSource Add & Remove
If you're using a BindingSource then you should generally work with the BindingSource. I would do that unless there was a specific need to work with the original data source, which in this case there isn't. If you are going to work with the original data source then using the BindingSource at all doesn't really serve a purpose.
Also, there should be no need to make any manual changes to the grid. The whole point of data-binding is that what affects one affects the other. If you make changes to the data source then the grid should reflect those changes. I've never seen a situation where that didn't happen.
Finally, the past tense of "bind" is "bound", not "binded".
Re: [2005] BindingDataSource Add & Remove
Quote:
Finally, the past tense of "bind" is "bound", not "binded".
Lol doh!
Thanks for the input thats probably right.