Reputation: 1049
i have a listview and it's items source is a list . I want a user to pick only one item . When I set SelectionMode of the listview to single , the user can still select several items and it seems like the listview is going crazy and selects items that user didn't select... looks very strange... can anyone know what could be the problem?
I cann't paste here a screenshot , i don't have the paste option.....
this is a xaml -
<StackPanel MinWidth="600" Margin="0,0,0,10" HorizontalAlignment="Left" Width="600">
<GroupBox Header="Command Queue" BorderThickness="0" Foreground="CornflowerBlue">
<Border BorderThickness="1.5" CornerRadius="10">
<ListView SelectionMode="Single" Background="Transparent" BorderThickness="0" Margin="5" Name="ListView_CmdQ" ItemsSource="{Binding}" MaxHeight="450" FontFamily="verdana" FontSize="12">
</ListView>
</Border>
</GroupBox>
</StackPanel>
Upvotes: 4
Views: 3863
Reputation: 4502
If your list_listItems contains the same string twice, you get this behavior. This happens with value types and reference strings. You should probably wrap each string in a TextBlock and put that in the listview.
It looks like this is reported as a bug still active (since 2007) here.
Upvotes: 0
Reputation: 34200
Do the items in your list appear more than once? I've seen this problem before where you have something like this:
var a = new Thing();
var b = new Thing();
var myList = new List<Thing>();
myList.Add(a);
myList.Add(b);
myList.Add(a);
myList.Add(b);
If you were to bind a ListView
to the myList
, you'd get the behaviour you've described. I think basically it's to do with the fact that multiple items in the list match the SelectedItem
, so the styling of the list gets a bit confused. One way around it is to wrap each item in another class:
var myList = new List<WrappedThing>();
myList.Add(new WrappedThing((a));
myList.Add(new WrappedThing((b));
myList.Add(new WrappedThing((a));
myList.Add(new WrappedThing((b));
... which means that each item in the list is unique, even though the item they're wrapping may not be.
Upvotes: 2