locked
How to select Grid/ListViewItems in C# when the parent Grid/ListView allows multiple selections RRS feed

  • Question

  • On my MainPage I have multiple ListViews and GridViews with different bits of a whole set of items however some items exist in multiple Views, so when my user selects or deselects one of these items I want that item in other views to also be selected or deselected. However all of these views have a multiple selection mode so I am struggling to do this.

    Here's what I'm trying to do:

    if (!GridView.SelectedItems.Contains(selectedItem))
    {
        GridView.SelectedItems.Add(selectedItem);
    }
    else
    {
        GridView.SelectedItems.Remove(selectedItem);
    }

    However this throws a 'catastrophic error' on either of these two lines of code.

    From what I've read on this I understand that SelectedItems is read only and so cannot be added to or removed from like this hence the error, so I was wondering if anyone can think of another way of doing this?

    I'm relatively inexperienced at this so keep the solutions simple please :) sample code would be awesome

    Thanks

    Wednesday, September 4, 2013 7:01 PM

Answers

  • Hi DomAyre,

    I wrote a really simple sample for you and I uploaded to skydrive: http://sdrv.ms/15B828C.

    If you open the project you will see left side is a ListView and right side is a GridView, while you select something in ListView, the same item will be selected on GridView, I think this is what you need.

    Any questions I'm willing to help,

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Thursday, September 5, 2013 8:53 AM
    Moderator