Beispiel #1
0
        /// <summary>
        /// 当拖动某项时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            Dictionary <ListViewItemEx, int> itemsCopy = new Dictionary <ListViewItemEx, int>();

            foreach (ListViewItemEx item in LvDataContent.SelectedItems)
            {
                itemsCopy.Add(item, item.Index);
            }
            LvDataContent.DoDragDrop(itemsCopy, DragDropEffects.Move);
        }
Beispiel #2
0
        /// <summary>
        /// 拖动时拖着某项置于某行上方时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView1_DragOver(object sender, DragEventArgs e)
        {
            // 获得鼠标坐标
            Point point = LvDataContent.PointToClient(new Point(e.X, e.Y));
            // 返回离鼠标最近的项目的索引
            int index = LvDataContent.InsertionMark.NearestIndex(point);

            // 确定光标不在拖拽项目上
            if (index > -1)
            {
                Rectangle itemBounds = LvDataContent.GetItemRect(index);
                if (point.X > itemBounds.Left + (itemBounds.Width / 2))
                {
                    LvDataContent.InsertionMark.AppearsAfterItem = true;
                }
                else
                {
                    LvDataContent.InsertionMark.AppearsAfterItem = false;
                }
            }
            LvDataContent.InsertionMark.Index = index;
        }