コード例 #1
0
        protected override void OnDragDrop(DragEventArgs e)
        {
            base.OnDragDrop(e);
            #if __ENABLE_DRAG_GHOST__
            IntPtr ownerWindow = Win32ImageList.GetDesktopWindow();
            Win32ImageList.ImageList_DragLeave(ownerWindow);
            #endif

            if (e.Data.GetDataPresent(typeof(ListViewItem[])))
            {
                ListViewItem[] dragData = (ListViewItem[])e.Data.GetData(typeof(ListViewItem[]));
                bool isUpper = false;
                Point p = this.PointToClient(new Point(e.X, e.Y));
                var item = getListItemByPoint(p, ref isUpper);

                int index = getInsertTargetIndex(dragData.First(), item, isUpper);

                if (index >= 0)
                {
                    //if (index >= this.Items.Count) index = this.Items.Count - 1;
                    System.Diagnostics.Debug.Print("OnDragDrop: index{0} �� index{1} �Ɉړ�", dragData.First().Index, index);
                    // ListItemMoving�C�x���g�𔭐������� �� �C�x���g������ŃL�����Z�������
                    var eventArg = new ListItemMovingEventArgs(dragData, index);
                    OnListItemMoving(eventArg);

                    if (eventArg.Cancel == false)
                    {
                        BeginUpdate();
                        foreach (ListViewItem listViewItem in dragData)
                            this.Items.Remove(listViewItem);
                        EndUpdate();

                        // ���X�g���ڂ�ړ�
                        foreach (ListViewItem listViewItem in dragData)
                        {
                            string name = listViewItem.Name; //ListItem#Clone()��Name�v���p�e�B�܂ŕ������Ȃ��̂ŁA��ōĐݒ肷��
                            ListViewItem insertedItem = this.Items.Insert(index, (ListViewItem)listViewItem.Clone());
                            insertedItem.Name = name;
                            insertedItem.Selected = true;
                            insertedItem.Focused = true;
                            index++;
                        }
                    }
                }

                m_prevItem = null;
                m_prevFlag = false;

                Invalidate(false);
            }
        }
コード例 #2
0
 protected virtual void OnListItemMoving(ListItemMovingEventArgs e)
 {
     if (this.ListItemMoving != null)
         this.ListItemMoving((object)this, e);
 }