RadListBox SelectionChanged EventHandler not Receiving Deselect Information

3 posts, 0 answers
  1. Geoffrey
    Geoffrey avatar
    2 posts
    Member since:
    Mar 2015

    Posted 07 May 2015 Link to this post

    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. Geoffrey
    Geoffrey avatar
    2 posts
    Member since:
    Mar 2015

    Posted 07 May 2015 Link to this post

    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.
  3. DevCraft banner
  4. Nasko
    Admin
    Nasko avatar
    588 posts

    Posted 11 May 2015 Link to this post

    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.

     
Back to Top