Alex Rivera | Logout

WPF Listview SelectionChanged event

Asked 2009-09-02T13:22:28.663
15

I have a ListView binding to an ItemsSource and the SelectionChanged event is firing on the load/databound events? I assume that it is because a 'default' items ie index 0 is selected.

How can I disable this?

Edit
Report

1 Answer

0

You can try to set the SelectedIndex property to -1 in your binding but this also is not an elegant solution.

<ListView PreviewMouseDown="ActiveCasesView_MouseDown" x:Name="ActiveCasesView"
                     DataContext="{StaticResource ActiveCasesViewSource}"
                     ItemsSource="{Binding}"
                     ItemTemplate="{StaticResource CasesItemTemplate}"
                     SelectionMode="Single"
                     SelectionChanged="ActiveCasesView_SelectionChanged"
                     ScrollViewer.CanContentScroll="True" 
                     ScrollViewer.VerticalScrollBarVisibility="Auto" 
**SelectedIndex="-1"**>
</ListView>

I tried to reproduce your behavior but without success. What is the Type of the ItemsSource collection that you are binding to?

answered 2009-09-03T14:20:20.443

Your Answer