ListView Windows 8 multiple indexes

2019-06-03 06:36发布

问题:

When you have a ListView in Windows 8 Metro Style Apps how can you get all the indexes selected supposing you have multiple selection enabled?

void itemsChanged (Platform::Object^ sender, 
      Windows::UI::Xaml::Controls::Controls::SelectionChangedEventArgs^ e 
{
    // get selected indexes
}

回答1:

You would have to compare the SelectedItems property of the sender (the ListView) with the Items property. It appears that SelectedItems add to the collection and remove from the collection in the order items were selected (although this is not documented anywhere I can find).



回答2:

You could add index properties to the type of item you bind to your ListView. Other than that - perhaps you don't really need an index?



回答3:

I found a solution with the suggestions received

auto v = itemsListView->SelectedItems;
auto l = itemsListView->Items;

std::list <unsigned int> v1;
for (int i=0; i < v->Size; i++)
{
            unsigned int k;
            l->IndexOf(v->GetAt(i),&k);
            v1.push_back(k);
}