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
e.Node.Override.Sort only works for node that arein standard view. When you bind the tree and it displays columns, it defaults to grid style. In that case, you have to sort a column, you can't sort a node, since the node itself wouldn't know which field to sort on.
Mike Saltzman"]In that case, you have to sort a column
That makes sense. Is there an example of how to sort a column for the tree? I am guessing it has to do with columnsets of something along those lines. I know how to do it in the WinGrid...just not as familar with the tree.
Yes, it has to do with ColumnSets. You are probably letting the tree create them automatically - which is what it does by default. So if you want the tree to start off sorted initially, what you could do is handle the ColumnSetGenerated event of the tree. This event will pass you in the ColumnSet that was created. You can examine the columns, find the one you want, and then set the Sort property on it.
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?