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
close icon

SfDatagrid Long-press context menu

Hello There,

I've been trying to add a context menu when clicking on a row of the datagrid. I used RegisterForContextMenu( ),  once I created the GridView to register and planned to create the context menu at overridden OnCreateContextMenu function. (See below) But it does not get triggered when I long press on a row. Any help would highly be appreciated.

       OrderInfoRepository viewModel = new OrderInfoRepository();
        SfDataGrid sfGrid;
        SfDataPager sfPager;
        Button btn;
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            sfGrid = FindViewById<SfDataGrid>(Resource.Id.sfDataGrid1);
            sfPager = FindViewById<SfDataPager>(Resource.Id.sfDataPager1);
            sfGrid.AutoGenerateColumns = false;
               ...

            RegisterForContextMenu(sfGrid);

        }

        public override void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo menuInfo)
        {
            // it does not trigger here
        }


        public override bool OnContextItemSelected(IMenuItem item)
        {
            // do my functions here
            return true;
        }

Attachment: MainActivity_e3e92841.zip

2 Replies

KK Karthikraja Kalaimani Syncfusion Team January 28, 2020 02:53 PM UTC

Hi Irantha,

Thank you for contacting Syncfusion support,

We have checked your requirement “Show ContextMenu in LongPress” and currently we are working on your requirement and we will update further details on 30th Jan 2020.

We appreciate your patience until then.

Regards,
Karthik Raja
 



KK Karthikraja Kalaimani Syncfusion Team January 30, 2020 02:53 PM UTC

Hi Irantha,

Thank you for contacting Syncfusion support,

We have checked your requirement “ContextMenu support in SfDataGrid” and we regret to tell currently we don’t have support for this requirement. As of now you can use SfPopup instead of ContextMenu while long press on SfDataGrid. Please refer the below code example.

Code  Example,

 
private SfDataGrid _dataGrid; 
        private ViewModel _viewModel; 
        private SfPopupLayout popup; 
        private System.Drawing.Point point; 
        protected override void OnCreate(Bundle savedInstanceState) 
        { 
            base.OnCreate(savedInstanceState); 
                       
            this.SetContentView(Resource.Layout.DataGridLayout); 
           point  = new System.Drawing.Point(); 
            popup = new SfPopupLayout(this); 
            popup.PopupView.ShowFooter = false; 
            popup.PopupView.ShowHeader = false; 
            popup.PopupView.HeightRequest = 200; 
            popup.PopupView.WidthRequest = 200; 
            popup.PopupView.PopupStyle.OverlayColor = Color.Transparent; 
            popup.ShowOverlayAlways = false; 
            _viewModel = new ViewModel(); 
            _dataGrid = FindViewById<SfDataGrid>(Resource.Id.sfDataGrid1); 
            _dataGrid.AutoGenerateColumns = true; 
            _dataGrid.ItemsSource = _viewModel.OrdersInfo; 
            _dataGrid.AllowResizingColumn = true; 
            _dataGrid.AllowSorting = true; 
            _dataGrid.SortColumnDescriptions.Add(new SortColumnDescription() 
            { 
                ColumnName = "OrderID", 
                SortDirection = ListSortDirection.Descending 
            }); 
 
            _dataGrid.GridLongPressed += _dataGrid_GridLongPressed; 
        } 
 
        private void _dataGrid_GridLongPressed(object sender, GridLongPressedEventArgs e) 
        { 
            
           point = SfDataGridHelpers.RowColumnIndexToPoint(_dataGrid, e.RowColumnIndex); 
            int x = point.X; 
            int y = point.Y; 
            popup.Show(x, y); 
        } 


Loader.
Live Chat Icon For mobile
Up arrow icon