ListViewDropTargetObserver::ListViewDropped
virtual void ListViewDropped ( const ListViewDropTargetEvent & 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 DragTab3Observer::ListViewDropped (const DG::ListViewDropTargetEvent& ev, DG::DragDrop::Effect* effect) { ULong i; short insertPos = ev.GetInsertPosition (); char* text; GS::VAArray<char*> textArray; // Array used to memorize list item texts GS::VAArray<const void*> iconArray; // Array used to memorize list item icons if (ev.HasDataFormat ('LVEX')) { DG::ListView* sourceList = ev.GetListViewSource (); // Getting the source listview control if (sourceList->GetId () != tabPage->listView.GetId () || sourceList->GetPanelId () != tabPage->listView.GetPanelId ()) sourceList->DisableDraw (); tabPage->listView.DisableDraw (); for (i = 0; i < ev.GetItemCount (); i++) { short listItem = ev.GetListViewItem (i); ULong size = sourceList->GetItemTextLength (listItem); text = BMAllocatePtr (size, ALLOCATE_CLEAR, 0); sourceList->GetItemText (listItem, text, size); textArray.Insert (i + 1, text); // Getting the text of the selected items if (sourceList->GetItemImageType (listItem) == DG::ListView::Icon) { DG::Icon icon = sourceList->GetItemIcon (listItem); iconArray.Insert (i + 1, icon.GetData ()); } } 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.GetListViewItem (j); sourceList->DeleteItem (listItem); if (listItem <= insertPos && sourceList->GetId () == tabPage->listView.GetId () && sourceList->GetPanelId () == tabPage->listView.GetPanelId ()) insertPos--; } } short tempInsPos = static_cast<short> (insertPos + 1); if (insertPos == DG::ListView::BottomItem) tempInsPos = insertPos; tabPage->listView.DeselectItem (DG::ListView::AllItems); // Deselect the original selection for (i = 0; i < ev.GetItemCount (); i++) { // Insert elements in the target list, than select them. tabPage->listView.InsertItem (tempInsPos); tabPage->listView.SelectItem (tempInsPos); tabPage->listView.SetItemText (tempInsPos, textArray[i + 1]); tabPage->listView.SetItemIcon (tempInsPos++, DG::Icon (iconArray[i + 1])); BMKillPtr (&textArray[i + 1]); } sourceList->EnableDraw (); sourceList->Redraw (); tabPage->listView.EnableDraw (); tabPage->listView.Redraw (); } }
Drop event handling in list view controls.