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.

GridGroupingControl Drag and Drop

Thread ID:

Created:

Updated:

Platform:

Replies:

69246 Oct 19,2007 01:36 PM Oct 30,2007 06:32 PM Windows Forms 3
loading
Tags: GridControl
Michael Sabin
Asked On October 19, 2007 01:36 PM

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

haneefm [Syncfusion]
Replied On October 19, 2007 05:01 PM

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

Michael Sabin
Replied On October 22, 2007 10:11 AM

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

haneefm [Syncfusion]
Replied On October 30, 2007 06:32 PM

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

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.

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.

;