This is a migrated thread and some comments may be shown as answers.

RadDragAndDropManager is that missing.

1 Answer 31 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Hugues
Top achievements
Rank 1
Hugues asked on 04 May 2015, 06:03 PM
I was looking for example on how to disable auto scrolling when trying to do drag and drop. I find that you can do so with  RadDragAndDropManager, so i start looking for it in winform version and i was not able to find that class at all. Is there a way to disable automatically scrolling of a RadListView when dragging from the listview to something else.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 May 2015, 10:42 AM
Hello Hugues,

Thank you for writing.

I suppose that you need ListViewDragDropService. In its HandleMouseMove method, the service performs scrolling when the mouse is outside the view. You can create a derivative of the ListViewDragDropService and override the mentioned method where you can perform the desired drag and drop functionality without scrolling. You can refer to our ListView >> Drag and Drop section in the online documentation which demonstrates how to customize the drag and drop behavior. Additionally, I have prepared a sample code snippet demonstrating how to modify the service in order to disable scrolling:
public Form1()
{
    InitializeComponent();
    new RadControlSpyForm().Show();
 
    for (int i = 0; i < 20; i++)
    {
        this.radListView1.Items.Add("Item" + i);
    }
 
    this.radListView1.AllowDragDrop = true;
 
    this.radListView1.AllowArbitraryItemHeight = false;
    this.radListView1.ItemSize = new Size(100, 40);
    this.radListView1.ListViewElement.DragDropService = new CustomListViewDragDropService(this.radListView1.ListViewElement);
}
 
public class CustomListViewDragDropService : ListViewDragDropService
{
    public CustomListViewDragDropService(RadListViewElement owner) : base(owner)
    {
    }
 
    protected override void HandleMouseMove(Point mousePos)
    {
        FieldInfo initializedField = typeof(RadDragDropService).GetField("initialized", BindingFlags.Instance | BindingFlags.NonPublic);
        
        if (!this.Initialized && ShouldBeginDrag(this.beginPoint.Value, mousePos))
        {
            initializedField.SetValue(this, this.PrepareContext());
        }
 
        if (!this.Initialized)
        {
            return;
        }
 
        MethodInfo mi = typeof(RadDragDropService).GetMethod("DoDrag", BindingFlags.NonPublic | BindingFlags.Instance) ;
        mi.Invoke(this, new object[] { mousePos });
        this.beginPoint = mousePos;
     
        FieldInfo fi = typeof(ListViewDragDropService).GetField("dragHintWindow", BindingFlags.NonPublic | BindingFlags.Instance);
        RadLayeredWindow dragHintWindow = fi.GetValue(this) as RadLayeredWindow;
        if (dragHintWindow == null && this.CanCommit)
        {
            this.PrepareDragHint();
        }
 
        this.UpdateDragHintLocation(mousePos);
    }
}

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
ListView
Asked by
Hugues
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or