I've recently been using data binding in c#, and while the way I am doing it is straightforward and works, it does not feel like the best way.
For example, I have a manager class, ie UserManager which has the following interface:
class UserManager
{
public IList<User> Users { get; ...}
public AddUser(...)
public RemoveUser(...)
}
So Adduser
and RemoveUser
should control the list, with the Users
collection as an output. I am using this collection in a binding, ie:
listBindingSource.DataSource = userManager.Users;
I am then manipulating the list via the binding, ie
listBindingSource.Add(new User(...))
This works, of course, but I am completely bypassing the UserManager
and the AddUser
/RemoveUser
functions in there! This of course seems very wrong. What is the correct way to use databinding?
UserManager
is inside a lib so I do not want to put any binding objects in there, as I feel that should be a gui thing. On the other hand, with binding, my gui has taken complete control over my collection.