Search
Calendar.CancelModify Method
See Also
 





Cancels an interactive modification of an item, previously started by a call to StartModify.

Namespace: MindFusion.Scheduling.WinForms
Assembly: MindFusion.Scheduling

 Syntax

C#  Copy Code

public bool CancelModify ()

Visual Basic  Copy Code

Public Function CancelModify () As Boolean

 Return Value

true if there was a started modification before the call; otherwise, false.

 Remarks

Through the use of the StartModify, UpdateModify, CompleteModify and CancelModify methods you can implement item drag operations within the Calendar control. This is useful in certain situations, such as when implementing OLE drag & drop operation over the Calendar control and you want the dragged item to be modified within the control before the drag & drop operation is complete.

 Example

The following code demonstrates how to implement the drag & drop scenario from the remarks section using these four methods. The sample assumes that the calendar variable already identifies a valid Calendar instance.

C#  Copy Code

// ...

private Appointment dragged = null;
private bool started = false;

/// <summary>
/// Handles the DragEnter event of the Calendar class.
/// </summary>
private void calendar_DragEnter(object sender, DragEventArgs e)
{
    dragged = new Appointment();
    dragged.StartTime = DateTime.MinValue;
    dragged.EndTime = dragged.StartTime + TimeSpan.FromDays(1);
    dragged.HeaderText = "Dragged appointment";
    calendar.Schedule.Items.Add(dragged);
    started = calendar.StartModify(dragged,
    calendar.PointToClient(new Point(e.X, e.Y)));
}

/// <summary>
/// Handles the DragLeave event of the Calendar class.
/// </summary>
private void calendar_DragLeave(object sender, EventArgs e)
{
    if (dragged != null)
    {
        calendar.CancelModify();
        calendar.Schedule.Items.Remove(dragged);
        dragged = null;
    }
}

/// <summary>
/// Handles the DragOver event of the Calendar class.
/// </summary>
private void calendar_DragOver(object sender, DragEventArgs e)
{
    if (dragged != null)
    {
        if (!started)
            started = calendar.StartModify(dragged, calendar.PointToClient(new Point(e.X, e.Y)));

        if (started)
        {
            calendar.UpdateModify(calendar.PointToClient(new Point(e.X, e.Y)));
            e.Effect = DragDropEffects.Copy;
            return;
        }
    }

    e.Effect = DragDropEffects.None;
}

/// <summary>
/// Handles the DragDrop event of the Calendar class.
/// </summary>
private void calendar_DragDrop(object sender, DragEventArgs e)
{
    if (dragged != null)
    {
        calendar.CompleteModify(calendar.PointToClient(new Point(e.X, e.Y)));
        dragged = null;

        calendar.UpdateLayout();
    }
}

// ...

Visual Basic  Copy Code

' ...

Private dragged As Appointment = Nothing
Private started As Boolean = False

' <summary>
' Handles the DragEnter event of the Calendar class.
' </summary>
Private Sub calendar_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles calendar.DragEnter

    dragged = New Appointment
    dragged.StartTime = DateTime.MinValue
    dragged.EndTime = dragged.StartTime.Add(TimeSpan.FromDays(1))
    dragged.HeaderText = "Dragged appointment"
    calendar.Schedule.Items.Add(dragged)
    started = calendar.StartModify(dragged, _
    calendar.PointToClient(New Point(e.X, e.Y)))

End Sub

' <summary>
' Handles the DragLeave event of the Calendar class.
' </summary>
Private Sub calendar_DragLeave(ByVal sender As Object, ByVal e As EventArgs) Handles calendar.DragLeave

    If Not dragged Is Nothing Then

        calendar.CancelModify()
        calendar.Schedule.Items.Remove(dragged)
        dragged = Nothing

    End If

End Sub

' <summary>
' Handles the DragOver event of the Calendar class.
' </summary>
Private Sub calendar_DragOver(ByVal sender As Object, ByVal e As DragEventArgs) Handles calendar.DragOver

    If Not dragged Is Nothing Then

        If Not started Then
            started = calendar.StartModify(dragged, calendar.PointToClient(New Point(e.X, e.Y)))
        End If

        If started Then

            calendar.UpdateModify(calendar.PointToClient(New Point(e.X, e.Y)))
            e.Effect = DragDropEffects.Copy
            Return

        End If

    End If

    e.Effect = DragDropEffects.None

End Sub

' <summary>
' Handles the DragDrop event of the Calendar class.
' </summary>
Private Sub calendar_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles calendar.DragDrop

    If Not dragged Is Nothing Then

        calendar.CompleteModify(calendar.PointToClient(New Point(e.X, e.Y)))
        dragged = Nothing

        calendar.UpdateLayout()

    End If

End Sub

' ...

 See Also