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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDatagrid Long-press context menu

Thread ID:

Created:

Updated:

Platform:

Replies:

150986 Jan 27,2020 11:34 AM UTC Jan 30,2020 02:53 PM UTC Xamarin.Android 2
loading
Tags: SfDataGrid
Irantha J
Asked On January 27, 2020 11:34 AM UTC

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

Karthikraja Kalaimani [Syncfusion]
Replied On 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
 


Karthikraja Kalaimani [Syncfusion]
Replied On 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); 
        } 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon