Link to home
Start Free TrialLog in
Avatar of marmaxx
marmaxx

asked on

Sorting a TreeViewControl

I need to sort a TreeView control based on one of two selected user options. The problem is, that the Text property of my TreeView nodes is set to a string that is actually a cocatenation of two database fields. For example, I am retrieving the followng values from my database: UserID, UserName, and displaying them in my TreeView like this: UserID - UserName.

I need to be able to sort by either of these fields.

I have looked at the TreeViewNodeSorter property, but haven't been able to figure out how to 'tweak' it to meet my needs.

Has anyone here done something similar?

Thanks!!
Avatar of 2266180
2266180
Flag of United States of America image

if I remember correctly, the treeview nodes/items have a property that can hold an object of any type (the type of that property is Object) you can create a wrapper class that will hold the 2 fields and set that treeview node's "object" property. then, in the custom sort event (delegate) you compare using that object from the node casted to the wrapper which will give you the 2 fields.
Avatar of marmaxx
marmaxx

ASKER

I believe we're talking about the same property - TreeViewListSorter. I tried your suggestion, but I'm still not having any luck. Would you be willing to post a small snippet, so that I can get a better idea of what you're taling about?

Thanks again for the feedback. I appreciate it.



ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of marmaxx

ASKER

Thank You!

I may have to tweak it a bit, but I get the idea. This should work for me.

I'm going to go ahead and award the points now since I'm sure I can use this.

I really appreciate you taking the time to provide the snippet.

glad to help :)