ListBoxDropTargetObserver::ListBoxDropped
virtual void ListBoxDropped (
const ListBoxDropTargetEvent & ev,
DragDrop::Effect * effect
);
Parameters
- ev
A reference to the event. - effect
Drag and drop effect can take the following values: DragDrop::Reject, DragDrop::Accept, DragDrop::Copy, DragDrop::Move, DragDrop::Link, DragDrop::Delete.
Description
Example
// Method Example:
void DragTab2Observer::ListBoxDropped (const DG::ListBoxDropTargetEvent& ev, DG::DragDrop::Effect* effect)
{
if (ev.GetSource () == &tabPage->listBox) {
ULong i;
short insertPos = ev.GetInsertPosition ();
char* text;
GS::VAArray<char*> textArray; //array used to memorize list item texts
if (ev.HasDataFormat ('FILE')) {
ULong nLocation = ev.GetLocationCount ();
char itemText[256];
sprintf (itemText, "%d ", nLocation);
tabPage->staticNumber.SetText (itemText);
tabPage->listBox.DeleteItem (DG::ListBox::AllItems);
for (ULong m = 0; m < nLocation; m++) {
IO::Location location;
if (ev.GetLocation (m, location)) {
IO::Path filename;
location.ToPath (&filename);
tabPage->listBox.AppendItem ();
tabPage->listBox.SetTabItemText (DG::ListBox::BottomItem, 1, filename);
}
}
} else if (ev.HasDataFormat ('LBEX') || ev.HasDataFormat ('LBDR')) {
DG::ListBox* sourceList = ev.GetListBoxSource (); // Getting the source listbox control
for (i = 0; i < ev.GetItemCount (); i++) {
short listItem = ev.GetListBoxItem (i);
ULong size = sourceList->GetTabItemTextLength (listItem, 1);
text = BMAllocatePtr (size, ALLOCATE_CLEAR, 0);
sourceList->GetTabItemText (listItem, 1, text, size);
textArray.Insert (i + 1, text); // Getting the text of the selected items
}
if (*effect == DG::DragDrop::Move) { // If move occurs than delete the selected elements from the source
for (long j = ev.GetItemCount () - 1; j >= 0 ; j--) {
short listItem = ev.GetListBoxItem (j);
sourceList->DeleteItem (listItem);
if (listItem <= insertPos && sourceList->GetId () == tabPage->listBox.GetId () &&
sourceList->GetPanelId () == tabPage->listBox.GetPanelId ())
insertPos--;
}
}
short tempInsPos = static_cast<short> (insertPos + 1);
tabPage->listBox.DeselectItem (DG::ListBox::AllItems); // Deselect the original selection
for (i = 0; i < ev.GetItemCount (); i++) { // Insert elements in the target list, than select them.
tabPage->listBox.InsertItem (tempInsPos);
tabPage->listBox.SelectItem (tempInsPos);
tabPage->listBox.SetTabItemText (tempInsPos++, 1, textArray[i + 1]);
BMKillPtr (&textArray[i + 1]);
}
}
}
}Dropped event handler for list box controls. This example includes file and list box drag source drag and drop operations.