예제 #1
0
        private void List_MouseMove(object sender, MouseEventArgs e)
        {
            // Get the current mouse position
            Point  mousePos = e.GetPosition(null);
            Vector diff     = startPoint - mousePos;

            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                // Get the dragged ListViewItem
                ListView     listView     = sender as ListView;
                ListViewItem listViewItem =
                    FindAnchestor <ListViewItem>((DependencyObject)e.OriginalSource);
                if (listViewItem != null)
                {
                    // Find the data behind the ListViewItem
                    HlpTable row = (HlpTable)listView.ItemContainerGenerator.
                                   ItemFromContainer(listViewItem);

                    // Initialize the drag & drop operation
                    DataObject dragData = new DataObject("myFormat", row);
                    DragDrop.DoDragDrop(listViewItem, dragData, DragDropEffects.Move);
                }
            }
        }
예제 #2
0
        private void DropList_Drop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent("myFormat"))
            {
                HlpTable     contact      = e.Data.GetData("myFormat") as HlpTable;
                ListView     listView     = sender as ListView;
                ListViewItem listViewItem =
                    FindAnchestor <ListViewItem>((DependencyObject)e.OriginalSource);

                // Find the data behind the ListViewItem
                HlpTable row = (HlpTable)listView.ItemContainerGenerator.
                               ItemFromContainer(listViewItem);

                row.Mapping          = contact.Mapping;
                listView.ItemsSource = sh.GetSelectTable[1].ColumnsList;
                ICollectionView view = CollectionViewSource.GetDefaultView(sh.GetSelectTable[1].ColumnsList);
                view.Refresh();
            }
        }