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
close icon

GridControl drag drop within grid

Hello,

I am using a virtual GridControl. In the grid, I support rows within the grid to be moved around using drag and drop (via the gridControl1_GridControlMouseDown and gridControl1_DragDrop) events. The grid also has the ListBoxSelectionMode Property set to MulitExtended.

My issue is that when I drop one row to another, I want the row I am dropping at to be selected when the drop ends. I manually set the row to be selected with the code below. But for some reason, the row I started the drag with will become selected. Is there any way that I can prevent this from happening?

gridControl1_DragDrop()
{
// .. do internal work to move row to drop row
this.gridControl1.Selections.Clear();
this.gridControl1.CurrentCell.MoveTo(GridRangeInfo.Row(dropRowNum));
this.gridControl1.Selections.Add(GridRangeInfo.Row(dropRowNum));
gridControl1.CurrentCell.ScrollInView();
}

3 Replies

LS Lingaraj S Syncfusion Team May 27, 2009 05:52 PM UTC

Hi Micheal,

Thank you for your interest in Syncfusion product.

The RowsMoved event is fired, when the row has been moved in the GridControl. Please try using your code into the RowsMoved event to achive the desired behaviour with the selection.

Please refer the code below:

this.gridControl1.RowsMoved += new GridRangeMovedEventHandler(gridControl1_RowsMoved);
void gridControl1_RowsMoved(object sender, GridRangeMovedEventArgs e)
{
this.gridControl1.Selections.Clear();
this.gridControl1.CurrentCell.MoveTo(GridRangeInfo.Row(dropRowNum));
this.gridControl1.Selections.Add(GridRangeInfo.Row(dropRowNum));
gridControl1.CurrentCell.ScrollInView();
}


Please let me know if you have any quereis.

Regards,
Lingaraj S.


AD Administrator Syncfusion Team May 27, 2009 08:00 PM UTC

Thanks, I tried that out but it didn't seem to work... The RowMoved event was never firing. I think that is because was was never doing any changes to moving the rows within the grid. Instead, i am modifying the internal model, and then calling grid refresh.

I found a hack where i set a timer after the drop event, and then move to the row in the timer_tick event. However, it is still a little jumpy. I can get away with using the hack, but if you can find a way to get it working properly, i would appreciate it.



LS Lingaraj S Syncfusion Team June 8, 2009 06:48 PM UTC

Hi Micheal,

Thank you for the update.

If you need the Selection changing after the drag operation in GridControl. You have handled the MouseDown event to perform the Drag operation in GridControl, so please try using conditional variables in MouseDown and MouseUp event to achieve this behavior.

We have created the sample to change the selection in GridControl, refer the sample in below link:
http://files.syncfusion.com/support/samples/Grid.Windows/Forums/VirtualSelection.zip

This sample demonstrate manually to select the Row in GridControl, when the Drag action has been performed in Selected row.

Let me know if you have any queries.

Regards,
Lingaraj S.

Loader.
Live Chat Icon For mobile
Up arrow icon