Reputation: 107
For each item in my listbox, I have a Button
and a TextBlock
. I can set my button to raise an event that removes an item from the ListBox, if I click on the TextBlock to highlight the item and then Remove(myListBox.SelectedItem)
.
However, I'm looking for a way to identify which item in the ListBox a specific Remove-Button is attached to, so I can RemoveAt(?)
when the event is raised.
Edit: Each of the buttons should remove the item on the line of that button without highlighting the line first. Therefore, using ListBox.SelectedItem is not a viable option :)
Upvotes: 0
Views: 96
Reputation: 69987
You can get the index of the item using the IndexOf
method:
YourCollection.RemoveAt(YourCollection.IndexOf(myListBox.SelectedItem));
Upvotes: 1