C
C#17mo ago
Donut5162

❔ WPF ListView with LinkedList

Hello, I have a ListView/GridView that is binded to a LinkedList. When I use the SelectedItem property of my ListView, it returns the value T of the LinkedListNode that is selected, and not the LinkedListNode itself, which is what I want. How do I get the LinkedListNode? I could just use the Find() method on my LinkedList with the T value to get the node I want, but I would like to avoid this as it is a linear time operation. Any help would be greatly appreciated!
7 Replies
HimmDawg
HimmDawg17mo ago
I believe this wont work because the enumeration for a LinkedList<T> goes over T and not LinkedListNode<T>
Donut5162
Donut5162OP17mo ago
Would making my own linked list class that implements IEnumerable work? (with the enumerator returning the node instead of the T value)
HimmDawg
HimmDawg17mo ago
Do you explicitly need the node?
Donut5162
Donut5162OP17mo ago
Well not really, I'm trying to make a song playlist editor. A linked list would be good for adding/removing songs at any position in constant time, and for that i would need the node itself
HimmDawg
HimmDawg17mo ago
I see. In that case you can make your own linked list that will enumerate over nodes instead of objects.
Donut5162
Donut5162OP17mo ago
Yeah. I'll try to do that. Thanks for your help
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server