How do i captured event when user click on ultra tree column header.
thanks in advanced. any suggestion appreciated.
There is no event that specifically corresponds to the end user clicking on a column header, but there is an AfterSortChange event which fires after a column is sorted. If your objective is to receive a notification when a column is sorted, that is the event you should handle.
You can also handle the MouseDown event and hit test for an element of type UltraTreeNodeColumnHeaderUIElement, as demonstrated by the following code sample:
void ultraTree_MouseDown(object sender, MouseEventArgs e){ UltraTree tree = sender as UltraTree; UIElement controlElement = tree.UIElement; UIElement elementAtPoint = controlElement != null ? controlElement.ElementFromPoint( e.Location ) : null; UltraTreeNodeColumnHeaderUIElement headerElement = null;
while ( elementAtPoint != null ) { headerElement = elementAtPoint as UltraTreeNodeColumnHeaderUIElement; if ( headerElement != null ) break;
elementAtPoint = elementAtPoint.Parent; }
if ( headerElement != null ) { // If you get in here, the mouse was pressed over a column header. }}
Hi Brian,
I've got a very similar problem. I want to handle the Click event on the column header or either handle the SortEvent.
I've already handled the BeforeSortChange and AfterSortChange events, but that got me only close to the solution but not completely to it.
Here's what I'd like to do:
A column is sorted with a user-defined SortComparer. Its SortIndicator is off, the SortType may not be changed for this sortComparer.
However, if the user clicks this column it should be sorted by another user-defined SortComparer. From then on, clicking on the column changes the SortType. I'm aware that there is the solution of adding an invisible column and sorting this column by the first SortComparer, but my tree is quite large and this is the column that is always sorted by default so I'm fearing that this would slow down the whole program.
What I've already done is the following:
I handle the BeforeSortChange Event with the following Code
foreach (UltraTreeNodeColumn sortedColumn in e.SortedColumns) { if (sortedColumn.Key.Equals(Properties.Resources.ColumnNameKey) && sortedColumn.SortType == SortType.Descending && sortedColumn.SortComparer is NodeSorter) {
try { tree.EventManager.SetEnabled(TreeEventIds.BeforeSortChange, false); tree.EventManager.SetEnabled(TreeEventIds.AfterSortChange, false); UltraTreeNodeColumn nameColumn = tree.ColumnSettings.RootColumnSet.Columns[Properties.Resources.ColumnNameKey]; nameColumn.SortComparer = new StandardColumnSorter(); nameColumn.SortType = SortType.Ascending; nameColumn.ShowSortIndicators = DefaultableBoolean.True; // tree.Refresh(); this seems to cause some unreproducible update errors. } finally { tree.EventManager.SetEnabled(TreeEventIds.BeforeSortChange, true); tree.EventManager.SetEnabled(TreeEventIds.AfterSortChange, true); } } }
It nearly does everything that is required. My only problem is that the SortType will be Descending after the Sorting independent on the configured SortType in the BeforeSortChange Event.
I've also tried the approach you described above. But this led me to another problem. If the user changes the size of columns and depresses the left mouse button above this column header it will change it's sort type and possibly comparer which is very unexpected for the user.
Thanks in advance