How to get ordinal values of Gridview selected items RRS feed

  • Question

  • For example, I have five items in a gridview control and I select the first and last item. How can I get the ordinal values of the selected items (it should be 0 and 4 if zero-based)? It seems that the only way to get the selected items from a GridView control is call its member method SelectedItems().

    Saturday, October 20, 2012 2:48 PM


  • 1.- You typically invoke SelectedItems() from the event handler 'SelectionChanged'. This is an example of a GridView bound to a ItemsSource :

                      ItemsSource="{Binding Path=ItemList}" 
    2.- You then retrieve the index for each item in the item source using ItemCollection.IndexOf method
    • Marked as answer by Leonard Sunday, October 21, 2012 2:26 PM
    Sunday, October 21, 2012 6:46 AM