Abhilash J A

Abhilash J A

  • 530
  • 2.4k
  • 600.5k

How to get row id from listview on click row in wpf c#.net ?

Dec 18 2016 5:49 AM
 I have listview in wpf C#.net,
 
How can I get row id from this listview on click?
  1. <ListView Height="490"    
  2.               HorizontalAlignment="Left"    
  3.               Name="listView1"     
  4.               VerticalAlignment="Top"     
  5.               Width="780"         
  6.               ItemsSource="{Binding}"    
  7.               IsSynchronizedWithCurrentItem="True"      
  8.                Margin="10,48,0,10">  
  9.     <ListView.View>  
  10.         <GridView>  
  11.   
  12.             <GridView.Columns >  
  13.                 <GridViewColumn>  
  14.                     <GridViewColumn.CellTemplate>  
  15.                         <DataTemplate>  
  16.                             <CheckBox Tag="{Binding login_Id}"  />  
  17.                         </DataTemplate>  
  18.                     </GridViewColumn.CellTemplate>  
  19.                 </GridViewColumn >  
  20.                 <GridViewColumn Width="155px" DisplayMemberBinding="{Binding FirstName}" >  
  21.                     <GridViewColumn.Header>  
  22.                         <GridViewColumnHeader Tag="FirstName" Click="MenuItem_Click">User Name</GridViewColumnHeader>  
  23.                     </GridViewColumn.Header>  
  24.                 </GridViewColumn>  
  25.                 <GridViewColumn Width="155px" DisplayMemberBinding="{Binding Computer_Name}" Header="PC-Names" />  
  26.                 <GridViewColumn Width="154px" DisplayMemberBinding="{Binding IP_Address}" Header="IP Adress" />  
  27.                 <GridViewColumn Width="153px" DisplayMemberBinding="{Binding countID}">  
  28.                     <GridViewColumn.Header>  
  29.                         <GridViewColumnHeader Tag="countID" Click="MenuItem_Click">Documents Scanned</GridViewColumnHeader>  
  30.                     </GridViewColumn.Header>  
  31.                 </GridViewColumn>  
  32.                 <GridViewColumn Width="153px" DisplayMemberBinding="{Binding LogInTime}" >  
  33.                     <GridViewColumn.Header>  
  34.                         <GridViewColumnHeader Tag="LogInTime" Click="MenuItem_Click">Last Login</GridViewColumnHeader>  
  35.                     </GridViewColumn.Header>  
  36.                 </GridViewColumn>  
  37.             </GridView.Columns>  
  38.         </GridView>  
  39.     </ListView.View>  
  40.     <ListView.ItemContainerStyle>  
  41.         <Style TargetType="ListViewItem">  
  42.             <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListViewItem_PreviewMouseLeftButtonDown" />  
  43.         </Style>  
  44.     </ListView.ItemContainerStyle>  
  45. </ListView>    
  46.    
 I have tried, 
 
  1.    private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)  
  2.         {  
  3. //Here How can I get id ?  
  4.         }  
 
 

Answers (2)