Yahweh Posted May 2, 2007 Share Posted May 2, 2007 Basically, I'm storing a directory tree in an XML file and displaying it in a treeview.The XML file looks like this: <?xml version="1.0" encoding="utf-8"?><folder name="root"> <folder name="level1"> <folder name="level1.1"> <file name="kitties.aspx" /> <file name="bunnies.aspx" /> </folder> <file name="firstpage.aspx" /> <file name="secondpage.aspx" /> <file name="anotherpage.aspx" /> </folder> <folder name="level2"> <file name="somepage.aspx" /> <file name="default.aspx" /> </folder> <file name="default.aspx" /> <folder name="level3" /></folder> I can load the XML file into a treeview, but unfortunately, it doesn't display right. It sorts nodes in the order that I add them to the file, when I'd like to have them sorted alphabetically.Is there a convenient to way to sort my treeview? Link to comment Share on other sites More sharing options...
aspnetguy Posted May 2, 2007 Share Posted May 2, 2007 have you tried TreeView.Sort() ??? http://msdn2.microsoft.com/en-us/library/s...eview.sort.aspx Link to comment Share on other sites More sharing options...
jesh Posted May 2, 2007 Share Posted May 2, 2007 have you tried TreeView.Sort() ??? http://msdn2.microsoft.com/en-us/library/s...eview.sort.aspx And if you want to use your own comparer, this page might help:http://msdn2.microsoft.com/en-us/library/s...nodesorter.aspx Link to comment Share on other sites More sharing options...
Yahweh Posted May 3, 2007 Author Share Posted May 3, 2007 have you tried TreeView.Sort() ??? http://msdn2.microsoft.com/en-us/library/s...eview.sort.aspx Yes, actually I did. I found that article too, and I was sorely disappointed when my code didn't compile, it returned a the error 'Sort' is not a member of 'System.Web.UI.WebControls.TreeView'.I'm creating a website, not a desktop application. The sort method applies to System.Windows.Forms.Treeview, but not to System.Web.UI.WebControls.Treeview. See for yourself.I think maybe a programmer at Microsoft was lazy and forgot to add that little function to the TreeView web control. Link to comment Share on other sites More sharing options...
aspnetguy Posted May 3, 2007 Share Posted May 3, 2007 Sorry, I did't realize that. I find that from time to time...for instance desktop apps can have a folder browser but web apps can't (as of .Net 1.1 anyways ) Link to comment Share on other sites More sharing options...
jesh Posted May 3, 2007 Share Posted May 3, 2007 This requires a bit more overhead, but can you load the XML file into a DataTable, sort the records with a DataView, and then use that DataView as the data source that you bind to the TreeView? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.