|
Sorting
Thursday, 20 August 2009
Flexible TreeView supports flexible nodes sorting without additional programming.
If the treeview contains columns, then sorting will follow these rules:
Automatic re–sorting will take place when:
If the treeview doesn`t contain columns, then sorting will follow these rules:
Automatic re–sorting will take place when:
Flexible TreeView allows two ways of custom sorting:
Changing default nodes compare algorithm When the treeview is sorting nodes, it uses a callback method, defined in the treeview`s DefaultNodeComparer property, that is intended to compare two nodes. You can change it to your implementation to change nodes compare logic. Example: tree.DefaultNodeComparer = MyComparer; tree.ReSort(); // new node comparer where we move all checked nodes on top. eCompareResult MyComparer(Node pNode1, Node pNode2, SortOrder pSortOrder, SortContext pContext) { bool asc; if(pNode1.CheckState == pNode2.CheckState) return eCompareResult.Equal; asc = pSortOrder == SortOrder.Ascending; // move all checked nodes on top. if(pNode1.CheckState == eCheckState.Checked) return asc ? eCompareResult.Higher : eCompareResult.Lower; if(pNode2.CheckState == eCheckState.Checked) return asc ? eCompareResult.Lower : eCompareResult.Higher; // return default comparer`s result. return pContext.DefaultComparer(pNode1, pNode2, pSortOrder, pContext); }
Flexible TreeView allows you to completely replace the default sorting logic, allowing a programmer to implement it manually. To do that, just enable the Options.Sorting.ManualSort treeview property and subscribe to the ColumnSortOrderChanged treview event where you need to implement your sorting algorithm. Example: tree.Options.Sorting.ManualSort = true; tree.ColumnSortOrderChanged += tree_ColumnSortOrderChanged; void tree_ColumnSortOrderChanged(FlexibleTreeView pTreeview, ColumnSortOrderChangedEventArgs pArgs) { // custom sorting logic here }
|
|