)
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

How to un-select all other records and select current record alone prior to starting the drag drop operation in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: May 18, 2016 |
Last Revised Date: February 12, 2020

Select and unselect record while drag and drop

If you want to remove all the selected records from the selection and select only the current record for drag and drop, you can use the “TableControlMouseDown” event. Please refer the below code snippet.

C#

private void grid_TableControlMouseDown(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlMouseEventArgs e)
{
    GridGroupingControl grid = sender as GridGroupingControl;
    if (grid != null)
    {
        //Clear all the selected records from the selection.
        grid.Table.SelectedRecords.Clear();
        GridTableControl tableControl = grid.TableControl;
        Point pt = new Point(e.Inner.X, e.Inner.Y);
        int row, col;
        if (tableControl.PointToRowCol(pt, out row, out col))
        {
            GridTableCellStyleInfo style = tableControl.Model[row, col];
            //checking if the cell in which the MouseDown event is a RecordRowHeaderCell.
            //If yes, then begins the DragDrop operation.
            if ((style.TableCellIdentity.TableCellType == GridTableCellType.RecordRowHeaderCell
            || style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordRowHeaderCell)
            && style.TableCellIdentity.DisplayElement.ParentRecord != null)
            {
                //Add the Current record to the selection.
                grid.Table.SelectedRecords.Add(style.TableCellIdentity.DisplayElement.GetRecord());
                //Move the current cell to the clicked row col index.
                grid.TableControl.CurrentCell.MoveTo(row, col);
                //Refresh the grid to apply the changes.
                grid.Refresh();
                DragDropEffects ef = tableControl.DoDragDrop(new DataObject(grid.Table.SelectedRecords), DragDropEffects.All);
                if (ef == DragDropEffects.Move)
                {
                    //need to delete selection if you want to support this
                }
            }
        }
    }
}

VB

Private Sub grid_TableControlMouseDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlMouseEventArgs)
 Dim grid As GridGroupingControl = TryCast(sender, GridGroupingControl)
 If grid IsNot Nothing Then
  'Clear all the selected records from the selection.
  grid.Table.SelectedRecords.Clear()
  Dim tableControl As GridTableControl = grid.TableControl
  Dim pt As New Point(e.Inner.X, e.Inner.Y)
  Dim row, col As Integer
  If tableControl.PointToRowCol(pt, row, col) Then
   Dim style As GridTableCellStyleInfo = tableControl.Model(row, col)
   'Checking if the cell in which the MouseDown event is a RecordRowHeaderCell.
   'If yes, then begins the DragDrop operation.
    If (style.TableCellIdentity.TableCellType = GridTableCellType.RecordRowHeaderCell   OrElse style.TableCellIdentity.TableCellType = GridTableCellType.AlternateRecordRowHeaderCell) AndAlso style.TableCellIdentity.DisplayElement.ParentRecord IsNot Nothing Then
     'Add the Current record to the selection.
     grid.Table.SelectedRecords.Add(style.TableCellIdentity.DisplayElement.GetRecord())
     'Move the current cell to the clicked row col index.
     grid.TableControl.CurrentCell.MoveTo(row, col)
     'Refresh the grid to apply the changes.
     grid.Refresh()
     Dim ef As DragDropEffects = tableControl.DoDragDrop(New DataObject(grid.Table.SelectedRecords), DragDropEffects.All)
     If ef = DragDropEffects.Move Then
      'need to delete selection if you want to support this
     End If
    End If
   End If
 End If
End Sub

Show select the current record

Samples:

C#: DragDropSelection_C#

VB: DragDropSelection_VB

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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