Source code of the tutorial is available for download.
This example shows how to use the row drag and drop moving feature.
ASPX
<DayPilot:DayPilotGantt runat="server" ID="Gantt" ... RowMoveHandling="Notify" />
C#
protected void Gantt_OnRowMove(object sender, RowMoveEventArgs e) { const int max = Int32.MaxValue; // make sure it's greater than any other ordinal value Task sourceParent = Gantt.Tasks.FindParent(e.Source); Task targetParent = Gantt.Tasks.FindParent(e.Target); //DataRow sourceRow = DbGetTask(e.Source.Id); DataRow targetRow = Db.GetTask(e.Target.Id); string targetParentId = targetParent != null ? targetParent.Id : null; string sourceParentId = sourceParent != null ? sourceParent.Id : null; int targetOrdinal = (int) targetRow["ordinal"]; switch (e.Position) { case RowMovePosition.Before: Db.UpdateTaskParent(e.Source.Id, targetParentId, targetOrdinal); break; case RowMovePosition.After: Db.UpdateTaskParent(e.Source.Id, targetParentId, targetOrdinal + 1); break; case RowMovePosition.Child: Db.UpdateTaskParent(e.Source.Id, e.Target.Id, max); targetParentId = e.Target.Id; break; case RowMovePosition.Forbidden: break; default: throw new ArgumentOutOfRangeException(); } Db.CompactOrdinals(sourceParentId); if (sourceParentId != targetParentId) { Db.CompactOrdinals(targetParentId); } }
VB
Protected Sub Gantt_OnRowMove(ByVal sender As Object, ByVal e As RowMoveEventArgs) Const max As Integer = Int32.MaxValue ' make sure it's greater than any other ordinal value Dim sourceParent As Task = Gantt.Tasks.FindParent(e.Source) Dim targetParent As Task = Gantt.Tasks.FindParent(e.Target) 'DataRow sourceRow = DbGetTask(e.Source.Id); Dim targetRow As DataRow = Db.GetTask(e.Target.Id) Dim targetParentId As String = If(targetParent IsNot Nothing, targetParent.Id, Nothing) Dim sourceParentId As String = If(sourceParent IsNot Nothing, sourceParent.Id, Nothing) Dim targetOrdinal As Integer = DirectCast(targetRow("ordinal"), Integer) Select Case e.Position Case RowMovePosition.Before Db.UpdateTaskParent(e.Source.Id, targetParentId, targetOrdinal) Case RowMovePosition.After Db.UpdateTaskParent(e.Source.Id, targetParentId, targetOrdinal + 1) Case RowMovePosition.Child Db.UpdateTaskParent(e.Source.Id, e.Target.Id, max) targetParentId = e.Target.Id Case RowMovePosition.Forbidden Case Else Throw New ArgumentOutOfRangeException() End Select Db.CompactOrdinals(sourceParentId) If sourceParentId <> targetParentId Then Db.CompactOrdinals(targetParentId) End If End Sub