Articles in this section

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

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 to the code snippet below.


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

The screenshot below illustrates the drag-and-drop selection

Show select the current record

Samples:

C#: DragDropSelection_C#

VB: DragDropSelection_VB

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied