title: Get objects and SelectedIndex from ListViewItem
body: <p>I am trying to create a list view that I bind to an OservableCollection of class ticket. It creates the list fine, but when the item click event is fired the SelectedIndex is always -1. How can I get the index of the clicked item? Each item also has some objects inside of it. How do I get address ability to the objects inside the listviewitem. I can get the text from ticket object, but accessing the checkbox, or whatever object I might need to put in there is confusing me. This is a windows phone 8.1 project.</p>
  
  <p>Xaml code</p>
  
  <pre><code>&lt;Page
  x:Class="BindingTest.MainPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="using:BindingTest"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d"
  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"&gt;
  
  &lt;Grid&gt;
      &lt;ListView x:Name="LV" IsItemClickEnabled="True" ItemClick="LV_ItemClick"&gt;
          &lt;ListView.ItemContainerStyle&gt;
              &lt;Style TargetType="ListViewItem"&gt;
                  &lt;Setter Property="HorizontalContentAlignment" Value="Stretch"&gt;&lt;/Setter&gt;
              &lt;/Style&gt;
          &lt;/ListView.ItemContainerStyle&gt;
          &lt;ListView.ItemTemplate&gt;
              &lt;DataTemplate&gt;
                  &lt;Grid x:Name="LVIGrid"&gt;
                      &lt;Grid.RowDefinitions&gt;
                          &lt;RowDefinition Height="Auto"/&gt;
                      &lt;/Grid.RowDefinitions&gt;
                      &lt;Grid.ColumnDefinitions&gt;
                          &lt;ColumnDefinition Width="*"/&gt;
                          &lt;ColumnDefinition Width="*"/&gt;
                          &lt;ColumnDefinition Width="*"/&gt;
                          &lt;ColumnDefinition Width="*"/&gt;
                          &lt;ColumnDefinition Width="5*"/&gt;
                          &lt;ColumnDefinition Width="3*"/&gt;
                      &lt;/Grid.ColumnDefinitions&gt;
  
                      &lt;CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" 
                                MinWidth="0"/&gt;
                      &lt;TextBlock Grid.Column="1" Text="{Binding iflag}" 
                                 VerticalAlignment="Center" HorizontalAlignment="Center" 
                                 FontSize="36" /&gt;
                      &lt;TextBlock Grid.Column="2" Text="{Binding kflag}" 
                                 VerticalAlignment="Center" HorizontalAlignment="Center"
                                 FontSize="36"/&gt;
                      &lt;TextBlock Grid.Column="3" Text="{Binding qty}" 
                                 VerticalAlignment="Center" HorizontalAlignment="Right" 
                                 FontSize="36"/&gt;
                      &lt;TextBlock Grid.Column="4" Text="{Binding itemStr}" 
                                 VerticalAlignment="Center" HorizontalAlignment="Center" 
                                 FontSize="24"/&gt;
                      &lt;TextBlock Grid.Column="5" Text="{Binding priceStr}"
                                 VerticalAlignment="Center" HorizontalAlignment="Right"
                                 FontSize="24"/&gt;
                  &lt;/Grid&gt;
              &lt;/DataTemplate&gt;
          &lt;/ListView.ItemTemplate&gt;
      &lt;/ListView&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>C# code behind</p>
  
  <pre><code>namespace BindingTest
  {
  
  public sealed partial class MainPage : Page
  {
      public ObservableCollection&lt;ticket&gt; ticketCol;
      public MainPage()
      {
          this.InitializeComponent();
  
          this.NavigationCacheMode = NavigationCacheMode.Required;
          ticketCol = new ObservableCollection&lt;ticket&gt;()
          {
              new ticket(){iflag="I",kflag="k",qty="1",itemStr="Test Item",priceStr="9.99"},
              new ticket(){iflag="I",kflag="k",qty="2",itemStr="Test Item",priceStr="9.99"},
              new ticket(){iflag="I",kflag="k",qty="3",itemStr="Test Item",priceStr="9.99"},
              new ticket(){iflag="I",kflag="k",qty="4",itemStr="Test Item",priceStr="9.99"}
          };
          LV.ItemsSource = ticketCol;
      }
  
      /// &lt;summary&gt;
      /// Invoked when this page is about to be displayed in a Frame.
      /// &lt;/summary&gt;
      /// &lt;param name="e"&gt;Event data that describes how this page was reached.
      /// This parameter is typically used to configure the page.&lt;/param&gt;
      protected override void OnNavigatedTo(NavigationEventArgs e)
      {
          // TODO: Prepare page for display here.
  
          // TODO: If your application contains multiple pages, ensure that you are
          // handling the hardware Back button by registering for the
          // Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
          // If you are using the NavigationHelper provided by some templates,
          // this event is handled for you.
      }
  
      public void createTable()
      {
  
      }
  
      public class ticket
      {
          public string iflag { get; set; }
          public string kflag { get; set; }
          public string qty { get; set; }
          public string itemStr { get; set; }
          public string priceStr { get; set; }
  
      }
  
      private void LV_ItemClick(object sender, ItemClickEventArgs e)
      {
          string test = ((ticket)e.ClickedItem).itemStr;
  
          int index = LV.SelectedIndex;
      }
  }
  </code></pre>
  
  <p>}</p>