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

AITaskList – Responding to a user drag drop


1/2/2007

Developers can respond to the TaskListDragDrop event to automate the addition of new Task Items when the end user drops data onto the task list:

Our demo application uses the following code to achieve this:

private void TaskListDragDrop(object sender, DragEventArgs e, AITaskListDragEventArgs ItemArgs)
{
aiTaskItem aItem = new aiTaskItem();
DataGridViewRow Row = (DataGridViewRow)(e.Data.GetData(typeof(DataGridViewRow)));
aItem.Title = Row.Cells[0].Value.ToString();
aItem.Description = Row.Cells[1].Value.ToString();
aItem.Expanded = false;
if (ItemArgs.ClosestTaskItem != null) //was it dropped next to an item?
aiTaskList1.AddTaskItem(aItem, ItemArgs.ClosestTaskItem.Index);
else
aiTaskList1.AddTaskItem(aItem);
}


Let’s look at the important parts of the code:

As usual we create a new AITaskItem and edit the properties based on the type of data that was dropped onto the TaskList (this is of course dependent on the developer and the specific application).

Our drag drop event passes a custom EventArgs object called ‘ItemArgs’. Using this object we can access the exact position in the Task List where the user dropped the object:

ItemArgs.ClosestTaskItem.Index


Using this index we can call AddTaskItem to add a new item to the list at this index:

aiTaskList1.AddTaskItem(aItem, ItemArgs.ClosestTaskItem.Index);


For more information on the features of AITaskList refer to the readme.htm file included in the download.


< Blog Home