Question
I am using GTP.Net and I would like to ask is it possible to drag a time item to a control for example ListView? I want the time item to be able to move around (change start time) when the cursor is within the gantt chart. But if the time item is drag to the listview (or the mouse is drag to the listview), I need to pick up the time item text (which is being drag) and display it to the ListView and delete it (the time item being drag). Is it possible? Thanks a lot.
Answer
You want to switch from internal drag drop to “Normal” windows forms drag drop. No sweat.
In the code below we choose to cancel the started internal mouse move operation and instead start the Control drag drop.
We then treat another Gantt as a reciver, but this is where you should handle you listbox...
private void gantt1_OnTimeItemAreaMouseDown_1(object sender, System.Windows.Forms.MouseEventArgs e)
{
this.richTextBox1.Text = "gantt1_OnTimeItemAreaMouseDown\n" + this.richTextBox1.Text;
if (gantt1.TimeItemFromPoint(e.X,e.Y)!=null)
{
TimeItem thedraggedTimedItem=gantt1.TimeItemFromPoint(e.X,e.Y);
gantt1.TimeItemArea.DoDragDrop(thedraggedTimedItem,DragDropEffects.All);
gantt1.MouseMoveCancel();
}
}
private void TimeItemArea_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(PlexityHide.GTP.TimeItem)))
{
e.Effect=DragDropEffects.All;
}
}
private void TimeItemArea_DragDrop(object sender, DragEventArgs e)
{
this.richTextBox1.Text = "DROP\n" ;
GanttRow gr=gantt2.GanttRowFromY(gantt2.TimeItemArea.PointToClient(new Point(0,e.Y)).Y);
//GanttRow gr=null;
//Cell c=gantt2.Grid.GridStructure.CellFromXY(0,e.Y);
//if (c!=null)
// gr=GanttRow.FromGridNode(c.Node);
if (e.Data.GetDataPresent(typeof(PlexityHide.GTP.TimeItem)) && gr!=null)
{
TimeItem theOneToMove=e.Data.GetData(typeof(PlexityHide.GTP.TimeItem)) as TimeItem;
TimeItem nti=gr.Layers[0].AddNewTimeItem();
nti.Start=theOneToMove.Start;
nti.Stop=theOneToMove.Stop;
}
}
}