Question
Hi,
I want to add a new time item by Mouse clicking and dragging.
Is it possible and so How-To ?
Thank you .
Answer
Yes you can do this by entering a special mouse mode: EnterTimeItemCreateMode
I recently did this in a data bounded Gantt and then you actually do not want the time item created but get all info about it so that you can create the underlaying object that in turn shows up in Gantt as a time item, seconds later.
I first implemented the OnTimeItem_OnBeforeMouseModeUse event to enter the EnterTimeItemCreateMode if the context was right:
private void gantt1_OnTimeItem_OnBeforeMouseModeUse(PlexityHide.GTP.Gantt aGantt, PlexityHide.GTP.TimeItemEventArgs e)
{
if (e.TimeItem==null)
{
GanttRow gr=gantt1.GanttRowFromPoint(new Point(e.x,e.y));
if (gr!=null)
{
if ((gr.GridNode.ListItemWhenDataBound() as RenderedTuple).Element.AsObject is Task)
gantt1.EnterTimeItemCreateMode(true,null,0);
}
}
}
I then caught the created time item, got all the data that I needed from it and then threw it away, and exited the special mouse mode:
private void gantt1_OnTimeItem_AfterCreateByMouse(PlexityHide.GTP.Gantt aGantt, PlexityHide.GTP.TimeItemEventArgs e)
{
if (e.TimeItem.Stop>e.TimeItem.Start.AddHours(8))
{
// If the time item created was of considerable length...
TaskTime taskTime=new TaskTime(projPlannerMain.EcoSpace);
object x=(e.TimeItem.GanttRow.GridNode.ListItemWhenDataBound() as RenderedTuple).Element.AsObject;
taskTime.OwningTask=(x as Task);
taskTime.Start=e.TimeItem.Start;
taskTime.Stop=e.TimeItem.Stop;
}
e.TimeItem.Layer.Remove(e.TimeItem);
gantt1.EnterTimeItemCreateMode(false,null,0);
}