Witam,
Mam formularz z dwioma obiektami typu listview, dajmy listviewGrups i listviewAccounts. Musze dodac obsluge 2 wydarzen drag&drop:
- Zmiana kolejnosci grup - czyli listviewGrups wysyla item i jednoczesnie jest jego odbiorca.
- Alokacja konta do grupy - listviewAccounts jest nadawca, a listviewGrups odbiorca.
Jak w metodzie listViewGroups_DragDrop(object sender, DragEventArgs e) moge pobrac informacje o zrodle (tj. z ktorego listview pochodza upuszczane elementy)?
Kod:
private void listViewGroups_ItemDrag(object sender, ItemDragEventArgs e)
{
listViewGroups.DoDragDrop(listViewGroups.SelectedItems, DragDropEffects.Move);
}
private void listViewGroups_DragEnter(object sender, DragEventArgs e)
{
//as propsed by Microsoft
int len = e.Data.GetFormats().Length - 1;
for (int i = 0; i <= len; i++)
{
if (e.Data.GetFormats()[i].Equals("System.Windows.Forms.ListView+SelectedListViewItemCollection"))
{
//The data from the drag source is moved to the target.
e.Effect = DragDropEffects.Move;
}
}
}
private void listViewGroups_DragDrop(object sender, DragEventArgs e)
{
//Return if the items are not selected in the ListView control.
if (listViewGroups.SelectedItems.Count == 0)
return;
//Returns the location of the mouse pointer in the ListView control.
Point cp = listViewGroups.PointToClient(new Point(e.X, e.Y));
//Obtain the item that is located at the specified location of the mouse pointer.
ListViewItem dragToItem = listViewGroups.GetItemAt(cp.X, cp.Y);
if (dragToItem == null)
return;
//Obtain the index of the item at the mouse pointer.
int dragIndex = dragToItem.Index;
*** TUTAJ MUSZE ROZPOZNAC ZRODLO ***
}
private void listViewAccounts_ItemDrag(object sender, ItemDragEventArgs e)
{
listViewAccounts.DoDragDrop(listViewAccounts.SelectedItems, DragDropEffects.Move);
}
Niestety, ale taki kod:
ListView source = sender as ListView;
MessageBox.Show(source.Name);
zwraca mi zawsze listviewGroups, a nigdy listviewAccounts.
Bede wdzieczny za Wasza pomoc.