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.
Unfortunately, activation email could not send to your email. Please try again.

How to detect which header is clicked on

Thread ID:

Created:

Updated:

Platform:

Replies:

127671 Dec 1,2016 11:38 AM Dec 2,2016 06:45 AM UWP 1
loading
Tags: SfDataGrid
David Harvey
Asked On December 1, 2016 11:38 AM

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.

Jai Ganesh S [Syncfusion]
Replied On December 2, 2016 06:45 AM

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;