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

GridGroupingControl Drag and Drop

I am using a GridGroupingControl grid in which drag and drop is used to move around records. This is accomplished by using a sort column in the underlying datasource and ordering the records by the sort column.

In the DragDrop event of the grid, I do the work to update the sort column of the dragged record, so the records will be in the new order.

My issue is that something is causing the record where the dragged record used to live to be selected. This occurs after the DragDrop event handler, and will occur even if I manually set the current record to be the one where the record is dropped in the handler. I.E. if I drag the 9th row to the 5th row (this will make the drag row the 4th row), the 9th row gets selected after the event.

Is there a way to prevent this, and make either the dragged or drop row selected?

Thanks

3 Replies

HA haneefm Syncfusion Team October 19, 2007 09:01 PM UTC

Hi Michael,

Please try calling the below code snippet after calling the tableControl.DoDragDrop method in TableControlMouseDown event. Below are the codes

//TableControlMouseDown event handler
DragDropEffects ef = tableControl.DoDragDrop(new DataObject(grid.Table.SelectedRecords), DragDropEffects.All);
Point DragPoint = e.TableControl.PointToClient(Control.MousePosition);
if (e.TableControl.PointToRowCol(DragPoint, out row, out col))
{
GridTableCellStyleInfo DragElementstyle = e.TableControl.GetTableViewStyleInfo(row, col);
if (DragElementstyle != null)
{
Element DragElement = DragElementstyle.TableCellIdentity.DisplayElement;
if (DragElement.Kind == DisplayElementKind.Record)
{
DragRecord = DragElement.GetRecord();
tableControl.CurrentCell.MoveTo(row, col);
tableControl.CurrentCell.BeginEdit();
tableControl.CurrentCell.Lock();
e.TableControl.MouseMove += new MouseEventHandler(TableControl_MouseMove);
}
}
}

Record DragRecord = null;
private bool IsLocked = false;
void TableControl_MouseMove(object sender, MouseEventArgs e)
{
if (IsLocked)
{
GridTableControl tc = sender as GridTableControl;
tc.CurrentCell.Unlock();
IsLocked = false;
DragRecord.SetSelected(true);
}
}

Please refer to the attached sample for implementation and let me know if this helps.
DragDrop_GGCSelectDragRow.zip

Best regards,
Haneef


MS Michael Sabin October 22, 2007 02:11 PM UTC

Thanks, that does help with getting the dropped record selected. However, I am still left with the original record selected. Is there a way to remove this.

Also, is there any way to scroll through the grid as you drag the record towards the top or bottom.

Thanks


HA haneefm Syncfusion Team October 30, 2007 10:32 PM UTC

Hi Michael,

Scrolling the record during the draganddrop process:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
To scroll the grid record during the drag and drop process, you need to handle the DragOver event of the grid and set the TableControl.TopRowIndex property. Below are the codes:

private void grid_DragOver(object sender, DragEventArgs e)
{
// showing the dragdrop effects.
if(e.Data.GetDataPresent(typeof(SelectedRecordsCollection)))
{
e.Effect = DragDropEffects.Copy;
}
Point pt = this.gridGroupingControl1.TableControl.PointToClient(Control.MousePosition);
int rowIndex, colIndex;
this.gridGroupingControl1.TableControl.PointToRowCol(pt, out rowIndex, out colIndex);
if (rowIndex == this.gridGroupingControl1.TableControl.TopRowIndex)
{
this.gridGroupingControl1.TableControl.TopRowIndex--;
}
else if ( rowIndex == this.gridGroupingControl1.TableControl.ViewLayout.LastVisibleRow )
this.gridGroupingControl1.TableControl.TopRowIndex++;
}

De-select the original record :
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Try calling the Table.SelectedRecords.Clear() method before calling the SetSelected() method in TableControl.MouseMove event. Below are the codes:

void TableControl_MouseMove(object sender, MouseEventArgs e)
{
GridTableControl tc = sender as GridTableControl;
if (IsLocked)
{
tc.CurrentCell.Unlock();
IsLocked = false;
tc.Table.SelectedRecords.Clear();
DragRecord.SetSelected(true);
}
}

Here is a sample for your reference.
ModifiedDragDrop_GGCSelectDragRow.zip

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon