This is a migrated thread and some comments may be shown as answers.

RadListBox SelectionChanged EventHandler not Receiving Deselect Information

2 Answers 103 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Geoffrey
Top achievements
Rank 1
Geoffrey asked on 07 May 2015, 12:32 PM

Hi

 I'm trying to wire up a SelectionChanged handler for my ListBox. I'm using SelectionMode="Multiple" and when I select an item, sure enough the event handler gets called with the AddedItems collection containing the item I selected. However, when I click on that item again, which should deselect the item and remove it from the selection, it instead calls through to the event handler with the item still listed in the AddedItems collection and not in the RemovedItems collection.

<telerik:RadListBox x:Name="ParentItemsList" ItemsSource="{Binding ParentItems}" SelectionMode="Multiple"                                                      SelectionChanged="ParentItemsListSelectionChanged" >                                <telerik:RadListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Horizontal">
        ...
      </StackPanel>
    </DataTemplate>
  </telerik:RadListBox.ItemTemplate>
</telerik:RadListBox>

private void ParentItemsListSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
  foreach (var item in e.AddedItems)
  {
    //multiple hits here, removed items are listed in the AddedItems collection
    ...
  }
  foreach (var item in e.RemovedItems)
  {
    //never reaches here
    ...
  }
}

2 Answers, 1 is accepted

Sort by
0
Geoffrey
Top achievements
Rank 1
answered on 07 May 2015, 03:25 PM
Not to worry, I discovered the cause of the problem. In this case I hadn't implemented the Equal override correctly for the objects in my databound collection. So the ListBox assumes that every time I select an object it is a new one instead of one it has already marked as selected.
0
Nasko
Telerik team
answered on 11 May 2015, 07:49 AM
Hi Geoffrey,

We are glad to hear that you were able to achieve the desired and now everything works as expected.

If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

Regards,
Nasko
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
ListBox
Asked by
Geoffrey
Top achievements
Rank 1
Answers by
Geoffrey
Top achievements
Rank 1
Nasko
Telerik team
Share this question
or