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.
Syncfusion Feedback

SfDataGrid right-clicking on multiple rows

Thread ID:

Created:

Updated:

Platform:

Replies:

116301 May 13,2014 08:52 AM UTC May 16,2014 12:22 PM UTC WinRT 2
loading
Tags: SfDataGrid
tahseen tarafdar
Asked On May 13, 2014 08:52 AM UTC

Hello,

When I ctrl+click multiple rows on my sfDataGrid and then right-click, I lose the multiple row selection and instead only the row I right-clicked on is selected. Is there anyway to keep all the rows selected? I'm using syncfusion version 12.1.0.43 for .NET 4.0. I tried the following but it didn't work:

    public partial class MainWindow : Window
    {
        private RowViewModel[] _previewSelection;

        public MainWindow()
        {
            InitializeComponent();
            
            //this is to make the cell selection more Excel like.
            DataGrid.PreviewMouseRightButtonDown += HandlePreviewRightMouseDown;
            DataGrid.ContextMenuOpening += HandleContextMenuOpening;

            ...
        }

        
        private void HandlePreviewRightMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (DataGrid.SelectedItems.Any())
            {
                _previewSelection = DataGrid.SelectedItems.OfType<RowViewModel>().ToArray();
            }
            else
            {
                _previewSelection = new RowViewModel[0];
                DataGrid.ContextMenu = null;
            }
        }


        private void HandleContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            foreach (var selected in _previewSelection)
            {
                if (!DataGrid.SelectedItems.Contains(selected))
                {
                    DataGrid.SelectedItems.Add(selected);
                }
            }
        }

        ...
    }



Jayapradha S [Syncfusion]
Replied On May 14, 2014 01:04 PM UTC

Hi Tahseen ,

 

We are able to reproduce the problem “Selection cleared when right click on the multiple selection of rows” and have logged defect report regarding this.

 

The fix for this issue will be included in our upcoming release Vol 2 which is scheduled in end of June 2014.

 

Please let usknow if you have any questions.

 

Regards,

Jayapradha


Jayapradha S [Syncfusion]
Replied On May 16, 2014 12:22 PM UTC

Hi Tahseen,

 

We analyzed your requirement once again and you can achieve this by using the below code snippet.  

 

Code snippet:

this.sfDataGrid.PreviewMouseRightButtonDown += sfDataGrid_PreviewMouseRightButtonDown;

this.sfDataGrid.CurrentCellActivating+=sfDataGrid_CurrentCellActivating;

this.sfDataGrid.CurrentCellBeginEdit+=sfDataGrid_CurrentCellBeginEdit;


bool
rightbuttonpressed = false;

void sfDataGrid_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)

{

    rightbuttonpressed = true;

}

 

private void sfDataGrid_CurrentCellActivating(object sender, Syncfusion.UI.Xaml.Grid.CurrentCellActivatingEventArgs args)

{

    if (rightbuttonpressed)

    {

        this.sfDataGrid.Dispatcher.BeginInvoke(new Action(() =>

        {

            rightbuttonpressed = false;

        }), DispatcherPriority.ApplicationIdle);

        args.Cancel = true;

    }

}

 

private void sfDataGrid_CurrentCellBeginEdit(object sender, CurrentCellBeginEditEventArgs args)

{

    if (rightbuttonpressed)

    {

        rightbuttonpressed = false;

        args.Cancel = true;

    }

}

 

We are assuming that your query is related to WPF SfDataGrid, but this forum placed under WinRT SfDataGrid. So could you please let us know the platform used whether it is WPF/Win RT?

 

Please let us know if this code snippet helps you.

 

Regards,

Jayapradha 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.

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

;