I have a simple test here and cannot seem to get the nodes to accept sorting when they are bound. I even tried sorting the DataView of the table and binding to that but still no luck. Here is my example. I have 1 ultratree on the form called treeActive and am calling my Override.Sort =Ascending in the InitializeNode section:
Imports Infragistics.Win
Imports Infragistics.Win.UltraWinTree
Public tbl As New DataTable("FilesToBurn")
CreateDataSet()
AddRows()
treeActive.ExpandAll(ExpandAllType.Always)
'treeActive.Override.SortComparer = New NodeSorter(treeActive.Nodes(1), "Ascending")
'treeActive.Override.Sort = SortType.Ascending
End Sub
Dim c As DataColumn
With c
End With
tbl.Columns.Add(c)
c.AllowDBNull = False
c.AutoIncrement = True
c.ReadOnly = True
c = New DataColumn("FilePathCD")
c.MaxLength = 500
c = New DataColumn("DirGUID")
c.MaxLength = 50
'THIS SHOULD BE SET TO "<SOFTWARE LIBRARY>" IF IT IS FROM THE LIBRARY
'
c = New DataColumn("FileSizeInt")
dsFilesToBurn.Tables.Add(tbl)
dsFilesToBurn.Relations.Add(dr)
r("FileName") = "My InHouse App"
r("FileType") = "Folder"
r("FileNameGUID") = "1234"
dsFilesToBurn.Tables(0).Rows.Add(r)
r = dsFilesToBurn.Tables(0).NewRow
r("FileName") = "MyFile Folder"
r("FileNameGUID") = "1222"
r("FileName") = "BrownFile.exe"
r("FileType") = "File"
r("FileNameGUID") = "1212"
r("FileParentGUID") = "1234"
r("FileSizeStr") = "54.2 MB"
r("FileName") = "ADumbFile.exe"
r("FileNameGUID") = "1616"
r("FileName") = "CoolFile.exe"
r("FileNameGUID") = "1414"
r("FileParentGUID") = "1222"
r("FileName") = "A New File.abc"
r("FileNameGUID") = "1111"
r("FileSizeStr") = "13.4 MB"
r("FileName") = "ABigFle.123"
r("FileNameGUID") = "1223"
r("FileSizeStr") = "700 MB"
r("FileName") = "NewAFile.exe"
r("FileNameGUID") = "1515"
r("FileName") = "JohnsFile.exe"
r("FileNameGUID") = "1717"
r("FileName") = "Some File.exe"
r("FileNameGUID") = "1181"
Try
If e.Node.IsRootLevelNode AndAlso e.Node.HasNodes Then
e.Node.Override.ShowExpansionIndicator = Infragistics.Win.UltraWinTree.ShowExpansionIndicator.CheckOnDisplay
End If
If (e.Node.Level = 0) AndAlso Not (e.Node.Cells("FileParentGUID").Value Is DBNull.Value) Then
e.Node.Visible = False
Else
e.Node.Visible = True
Catch
End Try
'JUST TRY TO SORT EVERYTHING ASCENDING
e.Node.Override.Sort = SortType.Ascending
End Class
The property you are looking for is called SortComparer and it's on the column.
"you can't sort a node, since the node itself wouldn't know which field to sort on"
In the standard .NET TreeView there is a TreeViewNodeSorter that can be replaced by a custom NodeSorter which derives from IComparer. This allows to sort the tree based upon information in the TreeNodeTag, for instance.
I am using an UltraTree in Outlook style (multicolumn), and I want to sort the tree using the TreeNodeTag. So here the node would indeed know which field to sort on. But there is no TreeViewNodeSorter property...
What should I do ?
Just so everyone knows here is the final solution I did for this. I have a datatable with several columns. However there is a FileType and FileName that I am worried about. FileType is either "File" or "Folder". I want Folders to be on top so I need the sort on this column to be DESC. However Filenames should be in order so they go ASC. Here is the event and the code to achieve this:
e.ColumnSet.Columns("FileType").SortType = SortType.Descending 'FOLDERS ON TOP
New items added to the datatable will also show up sorted automagically.
Nevermind...I got it. I was trying to target only the columnset that was my datatable. But that was the issue here. I just left it like this.
e.ColumnSet.Columns("FileName").SortType = SortType.Ascending
And it seems to work. I will play around with it. Thanks for the help!
I am doing this in the ColumnSetGenerated event:
If e.ColumnSet.Key = "FilesToBurn" Then 'THIS IS THE NAME OF MY TABLE
I checked and it does set the sort to Asc...but nothing actually happens. The data is still unsorted. I don't need to specify a custom sort comparer correct? It just doesn't appear to work. Any ideas?