views:

133

answers:

1

Hi, I am looking for a way of easily maintaining a list of Users belonging to a particular Group.
I have thought about using a Picklist, where I have 2 listboxs, the first contains a list of Users the second a list of Users belonging to the Group. There will be buttons to allow the adding and removing of selected Users from the Group. As users are added they move from the left listbox to the right, as they are removed they are move from the right to the list. This is pretty common situation.

Do you know of any examples of doing this in WPF using the MVVM pattern?

I am having difficulty understand how the binding may work to my View Model and Business Entities. Especially persisting the data back to the database. I am using stored procedure calls to do the CRUD logic, so I need to keep a list of which Users had been removed so I can delete them.

Is this the best way to perform this functionality or is there a better way. I simply want to pick from a list (the list may be large).

+1  A: 

This ought to be simple to implement. In your view model, create two observable collection properties, one containing users not in the group and one containing users that are. Also create selected-item properties for each collection. Bind the items controls' ItemsSource and SelectedItem properties to these properties. Then implement commands that remove the selected item from one collection and add it to the other, and bind those commands to your buttons.

The easiest way to keep track of which users have been removed is not to. When the time comes to update the database, compare the contents of your view model's collections with what's in your database. If an object's in your "not in group" collection and the database thinks it's in the group, remove it. If an object's in your "in group' collection and the database thinks it's not, add it.

Robert Rossney
thanks for the reply. Am I right in calling this kind of control a 'picklist' or is there a correct term for it?
Tim