Copyright Accelerated Ideas 2007 Legacy Blog Posts | Blog Home | .NET Components

AICalendar – Responding to drag drop operations


1/2/2007

Developers can respond to two events to perform drag drop operations:

Firstly, the AICalendarDragOver event is raised when the user drags an object over a day on the Calendar:

Our demo application responds to this event by firstly checking the type of data contained in the drag operation and secondly setting the accepted drag type to Copy only:

private void aiCalendar1_AICalendarDragOver(object sender, DragEventArgs e, AICalendarEventArgs DayPanelArgs)
{
string aString = (string)(e.Data.GetData(typeof(string)));
if (aString != null)
{
e.Effect = DragDropEffects.Copy;
}
}


Secondly, the AICalendarDragDrop event is fired when the end user drops the object onto a day on the Calendar. Developers should respond to this event and manipulate the affected DayPanel as desired.

Our demo application responds to this event by again checking the type of data and then using the DayPanelArgs object to manipulate the AIDayPanel that was affected:

private void aiCalendar1_AICalendarDragDrop(object sender, DragEventArgs e, AICalendarEventArgs DayPanelArgs)
{
string aString = (string)(e.Data.GetData(typeof(string)));
if (aString != null)
{

if (DayPanelArgs.DayPanel.Description != \"\")
{
DayPanelArgs.DayPanel.Description += \", \";
}
else //If the day hasn't been occupied yet..
{
//A holiday must have a nice colour of course!
if (aString == Extras[2])
DayPanelArgs.DayPanel.BlendColor = Color.LawnGreen;

if (aString == Extras[4])
DayPanelArgs.DayPanel.BlendColor = Color.LightCoral;

DayPanelArgs.DayPanel.Invalidate();
}

DayPanelArgs.DayPanel.Description += aString;

}
}


< Blog Home