开发者

MVVM, two synchronized Grid Data

I want to do a control for adding and removing items from a two list (Selected and UnSelected), like this:

MVVM, two synchronized Grid Data

But I can't find a good way to do this; how can I use the GridData (or similar control like GridControl of Devexpress) for bindi开发者_如何学运维ng two List and modify it?

Problems:

  • I can't use ObservableCollection with this control
  • I can't bind the SelectedItems

If you have any suggestion or sample for some work, it will be a great help


Can you use two observable collections? One for selected and one for unselected. It seems to be the easiest way to implement such functionality.

public class MainViewModel 
{
    private readonly ObservableCollection<Item> _selectedItems = new ObservableCollection();
    private readonly ObservableCollection<Item> _unselectedItems = new ObservableCollection();

    public IEnumerable<Item> SelectedItems { get { return _selectedItems; } }
    public IEnumerable<Item> UnselectedItems { get { return _unselectedItems; } }

    private void UnselectItems()
    {
        MoveFromOneCollectionToAnother(_unselectedItems, _selectedItems, ...);
    }

    private void SelectItems()
    {
        MoveFromOneCollectionToAnother(_selectedItems, _unselectedItems, ...);
    }

    private void MoveFromOneCollectionToAnother(ICollection<Item> source, ICollection<Item> destination, IEnumerable<Item> itemsToMove)
    {
        foreach (var item in itemsToMove)
        {
            source.Remove(item);
            destination.Add(item);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜