Jump to content

Sort A Treeview


Yahweh

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...