We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to detect which header is clicked on

I wish to add context sensitive menu to a right click event on a header, and therefore need to know which column header was clicked on.

In other words: Right clicking on a header should result in executing code that includes some information somewhere on which column header was clicked on.


Is this possible?

Thank you.

1 Reply

JG Jai Ganesh S Syncfusion Team December 2, 2016 11:45 AM UTC

Hi David, 
You can achieve your requirement for adding the context menu in column header and will get the details of the column header like below, 
 
syncfusion:SfDataGrid.HeaderContextMenu> 
                <MenuFlyout> 
                    <MenuFlyoutItem Text="Sort Ascending" Command="{Binding Path=DataContext.SortAscendingCommand}" CommandParameter="{Binding}" /> 
                </MenuFlyout> 
</syncfusion:SfDataGrid.HeaderContextMenu> 
 
private DelegateCommand _sortAscendingCommand; 
 
public DelegateCommand SortAscendingCommand 
{ 
    get 
    { 
        if (_sortAscendingCommand == null) 
            _sortAscendingCommand = new DelegateCommand(CanSortAscending, SortAscending); 
 
        return _sortAscendingCommand; 
    } 
    set { _sortAscendingCommand = value; } 
} 
 
private void SortAscending(object param) 
{ 
    if (param is GridColumnContextMenuInfo) 
    { 
        var grid = (param as GridContextMenuInfo).DataGrid; 
        var column = (param as GridColumnContextMenuInfo).Column; 
        grid.SortColumnDescriptions.Clear(); 
        grid.SortColumnDescriptions.Add(new SortColumnDescription() { ColumnName = column.MappingName, SortDirection = ListSortDirection.Ascending }); 
    } 
} 
 
 
Regards, 
Jai Ganesh S 


Loader.
Up arrow icon