Get the Selected RowIndex of Listview in WPF

Posted by Syedshakeer under WPF on 11/10/2010 | Points: 10 | Views : 8381 | Status : [Member] | Replies : 1
Hi,
How to get the selected Row Index of ListView in WPF.
When i try with listView1.SelectedIndex it returns -1.but not returning Row Index....

Below is my listview .xaml code

<ListView Name="listView1s" ItemContainerStyle="{StaticResource CustomListViewItemStyle}" ItemsSource="{Binding}>

<ListView.View>
<GridView AllowsColumnReorder="False" >
<GridView.ColumnHeaderContainerStyle>
<Style>
<Setter Property="FrameworkElement.Height" Value="23"/>
</Style>
</GridView.ColumnHeaderContainerStyle>

<GridViewColumn Width="70" Header="Job Id" >
<GridViewColumn.CellTemplate>
<DataTemplate >
<Label>
<Hyperlink Cursor="Hand" TextDecorations="None" Click="HyperLinkJobId_Click" Tag="{Binding JobID}">
<TextBlock Name="text" Text="{Binding JobID}" ToolTip="{Binding JobID}"></TextBlock>
</Hyperlink>
</Label>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
..........
.....................
....................
....
</ListView>




Syed Shakeer Hussain


Responses

Posted by: Abhi2434 on: 11/10/2010 [Member] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Always use ICollectionView to bind with ListView. Check my article :
http://www.abhisheksur.com/2010/08/woring-with-icollectionviewsource-in.html

I hope this will help.

www.abhisheksur.com

Syedshakeer, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response