0
votes
private void calendarPlanner1_ItemClick(object sender, WeekPlannerItemEventArgs e)
{
    DoDragDrop(calendarPlanner1.SelectedItem, DragDropEffects.Move);
}

private void calendarPlanner1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = DragDropEffects.Move;
}

private void calendarPlanner1_DragDrop(object sender, DragEventArgs e)
{
    SRRepair repairDrag = new SRRepair();
    var rows = calendarPlanner1.Rows;
    var row = rows.ElementAt(calendarPlanner1.SelectedRowIndex);
    row.Items.Add((WeekPlannerItem)e.Data.GetData(typeof(WeekPlannerItem)));
    repairDrag = assignedRepairsList[assignedItemCollection.IndexOf(calendarPlanner1.SelectedItem)];
    repairDrag.AssignedToUser = engineerList[calendarPlanner1.SelectedRowIndex];
    repairDrag.Update();
}

The code above is what I have so far for drag and drop operation. It works ok until the third (drag drop) method. Basically what im trying to achieve is to drag an item between the names. I could get the index where I drag the item from using 'calendar.SelectedRowIndex' but the problem is getting the index of the destination or where i want to drag it to. Allows me to drag items but when i let go of the left button in the mouse it goes back where it came from. The calendar is an open source and i found it from codeproject and i am using and modifying it to add it in an existing desktop application.

Is there anyway or an event I could use to get the position of the mouse as soon I release the left button in the mouse?

2

2 Answers

0
votes

I think, beside the drag and drop operation, you need to track your mouse move(or mouse enter) too, for getting the index of one element, drag'n'drop itself would not help(it get's the very first point), just track and identify the target by mouse move.

or simply, add mouse enter event for the object(controls) you want targeted by the drop, choose the target position via mouse enter, and complete the oration via drop, and it's better to remove mouse enter event when the drop operation completed, and add it by drop enter again.

hope I got your question true

0
votes

I'm pretty sure in a desktop application you can get the mouse position without having to rely on passed mouseevent arguments.

control.mouseposition - http://msdn.microsoft.com/en-us/library/system.windows.forms.control.mouseposition.aspx

you should just be able to get the 'point' value through 'control'.mouseposition. where the control is likely the form you're working with.

Edit

As stated in the reference, the control.mouseposition method is identical to this.cursor.position.

cursor.position - http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position.aspx

Additionally, you're going to want to locate the controls (plural), which are located at (or have ClientRectangle bounds that encompass) the cursor location point you capture..

control.GetChildAtPoint(Point).. which you may have to do recursively..

GetChildAtPoint - http://msdn.microsoft.com/en-us/library/ms158404.aspx