void table_DragEnter(object sender, DragEventArgs drgevent) { if (_table.UseBuiltInDragDrop) { if (!drgevent.Data.GetDataPresent(typeof(DragItemData).ToString())) { drgevent.Effect = _table.DragDropExternalTypeEffectSelector(sender, drgevent); } else { DragItemData data = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); if (!data.table.ExternalDropRemovesRows && (data.table != _table)) { drgevent.Effect = DragDropEffects.Copy; } else { drgevent.Effect = DragDropEffects.Move; } } _isStartDrag = true; } else { drgevent.Effect = _table.DragDropExternalTypeEffectSelector(sender, drgevent); } }
protected override void OnDragDrop(DragEventArgs drgevent) { if (!this.bool_0) { base.OnDragDrop(drgevent); } else { Point point = base.PointToClient(new Point(drgevent.X, drgevent.Y)); ListViewItem itemAt = base.GetItemAt(point.X, point.Y); if ((drgevent.Data.GetDataPresent(typeof(DragItemData).ToString()) && (((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).ListView != null)) && (((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).DragItems.Count != 0)) { DragItemData dragItemData = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); if ((this.processDragItemEventHandler_0 == null) || this.processDragItemEventHandler_0(dragItemData, itemAt)) { int num; ListViewItem item; if (itemAt == null) { for (num = 0; num < dragItemData.DragItems.Count; num++) { item = (ListViewItem)dragItemData.DragItems[num]; base.Items.Add(item); } } else { int index = itemAt.Index; if ((this == dragItemData.ListView) && (index > base.SelectedItems[0].Index)) { index++; } for (num = dragItemData.DragItems.Count - 1; num >= 0; num--) { item = (ListViewItem)dragItemData.DragItems[num]; base.Items.Insert(index, item); int num3 = ((index + 1) > (base.Items.Count - 1)) ? (base.Items.Count - 1) : (index + 1); base.Items[index].Position = base.Items[num3].Position; } } if (dragItemData.ListView != null) { foreach (ListViewItem item3 in dragItemData.ListView.SelectedItems) { dragItemData.ListView.Items.Remove(item3); } } this.Refresh(); if (this.listViewItem_0 != null) { this.listViewItem_0 = null; } base.Invalidate(); base.OnDragDrop(drgevent); } } } }
private DragItemData method_0() { DragItemData data = new DragItemData(this); foreach (ListViewItem item in base.SelectedItems) { data.DragItems.Add(item.Clone()); } return(data); }
private DragItemData GetDataForDragDrop(int nRow) { DragItemData data = new DragItemData(_table); Row rowData = new Row(); rowData = _table.TableModel.Rows[nRow]; data.DragItems.Add(rowData); return(data); }
private DragItemData GetDataForDragDrop() { // create a drag item data object that will be used to pass along with the drag and drop DragItemData data = new DragItemData(this); // go through each of the selected items and // add them to the drag items collection // by creating a clone of the list item foreach (ListViewItem item in this.SelectedItems) { data.DragItems.Add(item.Clone()); } return(data); }
private DragItemData GetDataForDragDrop() { // create a drag item data object that will be used to pass along with the drag and drop DragItemData data = new DragItemData(this); // go through each of the selected items and // add them to the drag items collection // by creating a clone of the list item foreach (ListViewItem item in this.SelectedItems) { object copied_item = item.Clone(); (copied_item as ListViewItem).Name = "copy_of_" + item.Name; //System.Diagnostics.Debug.Print("\n*********************************************\nName-"+(copied_item as ListViewItem).Name+"-End Name\n*********************************************\n"); data.DragItems.Add(copied_item); } return(data); }
protected override void OnDragDrop(DragEventArgs drgevent) { if (!m_allowReorder) { base.OnDragDrop(drgevent); return; } // get the currently hovered row that the items will be dragged to Point clientPoint = base.PointToClient(new Point(drgevent.X, drgevent.Y)); ListViewItem hoverItem = base.GetItemAt(clientPoint.X, clientPoint.Y); if (!drgevent.Data.GetDataPresent(typeof(DragItemData).ToString()) || ((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).ListView == null || ((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).DragItems.Count == 0) { return; } // retrieve the drag item data DragItemData data = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); //拖拉触发事件 if (ProcessDragItem != null && !ProcessDragItem(data, hoverItem)) { return;//如果没有处理通过,则不继续 } if (hoverItem == null) { // the user does not wish to re-order the items, just append to the end for (int i = 0; i < data.DragItems.Count; i++) { ListViewItem newItem = (ListViewItem)data.DragItems[i]; base.Items.Add(newItem); } } else { // the user wishes to re-order the items // get the index of the hover item int hoverIndex = hoverItem.Index; // determine if the items to be dropped are from // this list view. If they are, perform a hack // to increment the hover index so that the items // get moved properly. if (this == data.ListView) { if (hoverIndex > base.SelectedItems[0].Index) { hoverIndex++; } } // insert the new items into the list view // by inserting the items reversely from the array list for (int i = data.DragItems.Count - 1; i >= 0; i--) { ListViewItem newItem = (ListViewItem)data.DragItems[i]; base.Items.Insert(hoverIndex, newItem); int posIndex = hoverIndex + 1 > (base.Items.Count - 1) ? (base.Items.Count - 1) : hoverIndex + 1; base.Items[hoverIndex].Position = base.Items[posIndex].Position; } } // remove all the selected items from the previous list view // if the list view was found if (data.ListView != null) { foreach (ListViewItem itemToRemove in data.ListView.SelectedItems) { data.ListView.Items.Remove(itemToRemove); } } this.Refresh(); // set the back color of the previous item, then nullify it if (m_previousItem != null) { m_previousItem = null; } this.Invalidate(); // call the base on drag drop to raise the event base.OnDragDrop(drgevent); }
protected override void OnDragDrop(DragEventArgs drgevent) { if (!AllowDrop) { base.OnDragDrop(drgevent); return; } // get the currently hovered row that the items will be dragged to Point clientPoint = base.PointToClient(new Point(drgevent.X, drgevent.Y)); ListViewItem hoverItem = base.GetItemAt(clientPoint.X, clientPoint.Y); if (!drgevent.Data.GetDataPresent(typeof(DragItemData).ToString()) || ((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).ListView == null || ((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).DragItems.Count == 0) { return; } // retrieve the drag item data DragItemData data = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); bool isDragItemsChanged = false; if (hoverItem == null) { // the user does not wish to re-order the items, just append to the end for (int i = 0; i < data.DragItems.Count; i++) { ListViewItem newItem = (ListViewItem)data.DragItems[i]; if (this == data.ListView) { if (m_allowReorder) { base.Items.Add(newItem); isDragItemsChanged = true; } } else { DragItemEventArgs e = new DragItemEventArgs(); e.Item = newItem; this.OnDragItemAdding(e); if (!e.Cancel) { base.Items.Add(newItem); isDragItemsChanged = true; } } } } else { // the user wishes to re-order the items // get the index of the hover item int hoverIndex = hoverItem.Index; // determine if the items to be dropped are from // this list view. If they are, perform a hack // to increment the hover index so that the items // get moved properly. if (this == data.ListView) { if (hoverIndex > base.SelectedItems[0].Index) { hoverIndex++; } } // insert the new items into the list view // by inserting the items reversely from the array list for (int i = data.DragItems.Count - 1; i >= 0; i--) { ListViewItem newItem = (ListViewItem)data.DragItems[i]; if (this == data.ListView) { if (m_allowReorder) { base.Items.Insert(hoverIndex, newItem); isDragItemsChanged = true; } } else { DragItemEventArgs e = new DragItemEventArgs(); e.Item = newItem; this.OnDragItemAdding(e); if (!e.Cancel) { base.Items.Insert(hoverIndex, newItem); isDragItemsChanged = true; } } } } // remove all the selected items from the previous list view // if the list view was found if (data.ListView != null) { if (data.ListView == this && m_allowReorder || data.ListView != this && m_dragDropRemoveFromSource) { foreach (ListViewItem itemToRemove in data.ListView.SelectedItems) { data.ListView.Items.Remove(itemToRemove); } data.ListView.OnDragItemsChanged(new EventArgs()); } } // set the back color of the previous item, then nullify it if (m_previousItem != null) { m_previousItem = null; } if (m_allowReorder) { this.Invalidate(); } // call the base on drag drop to raise the event base.OnDragDrop(drgevent); if (isDragItemsChanged) { OnDragItemsChanged(new EventArgs()); } }
private DragItemData GetDataForDragDrop() { // create a drag item data object that will be used to pass along with the drag and drop DragItemData data = new DragItemData(this); // go through each of the selected items and // add them to the drag items collection // by creating a clone of the list item foreach(ListViewItem item in this.SelectedItems) { data.DragItems.Add(item.Clone()); } return data; }
// Methods private DragItemData GetDataForDragDrop() { DragItemData data = new DragItemData(this); foreach (System.Windows.Forms.ListViewItem item in base.SelectedItems) { data.DragItems.Add(item.Clone()); } return data; }
protected override void OnDragOver(DragEventArgs drgevent) { if (!m_allowReorder) { base.OnDragOver(drgevent); return; } if (!drgevent.Data.GetDataPresent(typeof(DragItemData).ToString())) { // the item(s) being dragged do not have any data associated drgevent.Effect = DragDropEffects.None; return; } if (((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).ListView == null) { return; } // retrieve the drag item data DragItemData data = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); // check if lock condition is ok if (m_lock != data.ListView.GetLockCode()) { // the item(s) being dragged do not have any data associated drgevent.Effect = DragDropEffects.None; return; } if (base.Items.Count > 0) { // get the currently hovered row that the items will be dragged to Point clientPoint = base.PointToClient(new Point(drgevent.X, drgevent.Y)); ListViewItem hoverItem = base.GetItemAt(clientPoint.X, clientPoint.Y); Graphics g = this.CreateGraphics(); if (hoverItem == null) { //MessageBox.Show(base.GetChildAtPoint(new Point(clientPoint.X, clientPoint.Y)).GetType().ToString()); // no item was found, so no drop should take place drgevent.Effect = DragDropEffects.Move; if (m_previousItem != null) { m_previousItem = null; Invalidate(); } hoverItem = base.Items[base.Items.Count - 1]; if (this.View == View.Details || this.View == View.List) { using (Pen pen = new Pen(m_lineColor, 2)) { g.DrawLine(pen, new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y + hoverItem.Bounds.Height), new Point(hoverItem.Bounds.X + this.Bounds.Width, hoverItem.Bounds.Y + hoverItem.Bounds.Height)); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y + hoverItem.Bounds.Height - 5), new Point(hoverItem.Bounds.X + 5, hoverItem.Bounds.Y + hoverItem.Bounds.Height), new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y + hoverItem.Bounds.Height + 5) }); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(this.Bounds.Width - 4, hoverItem.Bounds.Y + hoverItem.Bounds.Height - 5), new Point(this.Bounds.Width - 9, hoverItem.Bounds.Y + hoverItem.Bounds.Height), new Point(this.Bounds.Width - 4, hoverItem.Bounds.Y + hoverItem.Bounds.Height + 5) }); } } else { using (Pen pen = new Pen(m_lineColor, 2)) { g.DrawLine(pen, new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width, hoverItem.Bounds.Y + hoverItem.Bounds.Height)); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width - 5, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width + 5, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width, hoverItem.Bounds.Y + 5) }); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width - 5, hoverItem.Bounds.Y + hoverItem.Bounds.Height), new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width + 5, hoverItem.Bounds.Y + hoverItem.Bounds.Height), new Point(hoverItem.Bounds.X + hoverItem.Bounds.Width, hoverItem.Bounds.Y + hoverItem.Bounds.Height - 5) }); } } // call the base OnDragOver event base.OnDragOver(drgevent); return; } // determine if the user is currently hovering over a new // item. If so, set the previous item's back color back // to the default color. if ((m_previousItem != null && m_previousItem != hoverItem) || m_previousItem == null) { this.Invalidate(); } // set the background color of the item being hovered // and assign the previous item to the item being hovered //hoverItem.BackColor = Color.Beige; m_previousItem = hoverItem; if (this.View == View.Details || this.View == View.List) { using (Pen pen = new Pen(m_lineColor, 2)) { g.DrawLine(pen, new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X + this.Bounds.Width, hoverItem.Bounds.Y)); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y - 5), new Point(hoverItem.Bounds.X + 5, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y + 5) }); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(this.Bounds.Width - 4, hoverItem.Bounds.Y - 5), new Point(this.Bounds.Width - 9, hoverItem.Bounds.Y), new Point(this.Bounds.Width - 4, hoverItem.Bounds.Y + 5) }); } } else { using (Pen pen = new Pen(m_lineColor, 2)) { g.DrawLine(pen, new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y + hoverItem.Bounds.Height)); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(hoverItem.Bounds.X - 5, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X + 5, hoverItem.Bounds.Y), new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y + 5) }); } using (SolidBrush solidBrush = new SolidBrush(m_lineColor)) { g.FillPolygon(solidBrush, new Point[] { new Point(hoverItem.Bounds.X - 5, hoverItem.Bounds.Y + hoverItem.Bounds.Height), new Point(hoverItem.Bounds.X + 5, hoverItem.Bounds.Y + hoverItem.Bounds.Height), new Point(hoverItem.Bounds.X, hoverItem.Bounds.Y + hoverItem.Bounds.Height - 5) }); } } // go through each of the selected items, and if any of the // selected items have the same index as the item being // hovered, disable dropping. foreach (ListViewItem itemToMove in base.SelectedItems) { if (itemToMove.Index == hoverItem.Index) { drgevent.Effect = DragDropEffects.None; hoverItem.EnsureVisible(); return; } } // ensure that the hover item is visible hoverItem.EnsureVisible(); } // everything is fine, allow the user to move the items drgevent.Effect = DragDropEffects.Move; // call the base OnDragOver event base.OnDragOver(drgevent); }
private DragItemData GetDataForDragDrop(int nRow) { DragItemData data = new DragItemData(_table); Row rowData = new Row(); rowData = _table.TableModel.Rows[nRow]; data.DragItems.Add(rowData); return data; }
void table_DragDrop(object sender, DragEventArgs drgevent) { if (_table.UseBuiltInDragDrop) { if (drgevent.Data.GetDataPresent(typeof(DragItemData).ToString())) { Point point = _table.PointToClient(new Point(drgevent.X, drgevent.Y)); int nRow = -1; if (point.Y <= _table.HeaderHeight) { nRow = _table.TopIndex - 1; if (nRow < 0) { nRow = 0; } } else { nRow = _table.RowIndexAt(point); } Row hoverItem = _table.TableModel.Rows[nRow]; DragItemData data = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); int srcIndex = -1; if ((data.table == null) || (data.DragItems.Count == 0)) { _isStartDrag = false; _isMouseDown = false; _selectedRow = -1; return; } if (data.table != null) { if (data.table.SelectedIndicies.GetLength(0) > 0) { if (data.table.AllowDrop && ((data.table == _table) || (data.table.ExternalDropRemovesRows))) { data.table.TableModel.Rows.Remove(data.table.SelectedItems[0]); } _isMouseDown = false; _isStartDrag = false; if (data.table == _table) { srcIndex = _selectedRow; } _selectedRow = -1; _previousRow = null; } } if (hoverItem == null) { for (int i = 0; i < data.DragItems.Count; i++) { Row newItem = (Row)data.DragItems[i]; _table.TableModel.Rows.Add(newItem); _table.DragDropRowInsertedAt(_table.TableModel.Rows.Count - 1); } } else { for (int i = data.DragItems.Count - 1; i >= 0; i--) { Row newItem = (Row)data.DragItems[i]; if (nRow < 0) { _table.TableModel.Rows.Add(newItem); if (srcIndex < 0) { _table.DragDropRowInsertedAt(_table.TableModel.Rows.Count - 1); } else { _table.DragDropRowMoved(srcIndex, _table.TableModel.Rows.Count - 1); } } else { _table.TableModel.Rows.Insert(nRow, newItem); if (srcIndex < 0) { _table.DragDropRowInsertedAt(nRow); } else { _table.DragDropRowMoved(srcIndex, nRow); } } } } } else { _table.DragDropExternalType(sender, drgevent); } if (_previousRow != null) { _previousRow = null; } _table.Invalidate(); _isStartDrag = false; _isMouseDown = false; _selectedRow = -1; } else { _table.DragDropExternalType(sender, drgevent); } }
void table_DragOver(object sender, DragEventArgs drgevent) { //if (!drgevent.Data.GetDataPresent(typeof(DragItemData).ToString())) //{ // //drgevent.Effect = DragDropEffects.None; // return; //} if (_table.UseBuiltInDragDrop && _table.TableModel.Rows.Count > 0) { Point point = _table.PointToClient(new Point(drgevent.X, drgevent.Y)); int nRow = -1; if (point.Y <= _table.HeaderHeight) { nRow = _table.TopIndex - 1; if (nRow < 0) { nRow = 0; } } else { nRow = _table.RowIndexAt(point); } Row hoverItem = _table.TableModel.Rows[nRow]; Graphics g = _table.CreateGraphics(); if (hoverItem == null) { if (_previousRow != null) { _previousRow = null; _table.Invalidate(); } return; } if ((_previousRow != null && _previousRow != hoverItem) || _previousRow == null) { _table.Invalidate(); } _previousRow = hoverItem; if (drgevent.Data.GetDataPresent(typeof(DragItemData).ToString()) && _selectedRow == nRow && (((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).table == _table)) { drgevent.Effect = DragDropEffects.None; } else { if (drgevent.Data.GetDataPresent(typeof(DragItemData).ToString())) { DragItemData data = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); if (!data.table.ExternalDropRemovesRows && (data.table != _table)) { drgevent.Effect = DragDropEffects.Copy; } else { drgevent.Effect = DragDropEffects.Move; } } else if (!drgevent.Data.GetDataPresent(typeof(DragItemData).ToString())) { drgevent.Effect = _table.DragDropExternalTypeEffectSelector(sender, drgevent); } if (drgevent.Effect != DragDropEffects.None) { _renderer.PaintDragDrop(g, hoverItem, _table.RowRect(nRow)); } } _table.EnsureVisible(nRow, 0); } }
void table_DragDrop(object sender, DragEventArgs drgevent) { if (!drgevent.Data.GetDataPresent(typeof(DragItemData).ToString()) || ((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).table == null || ((DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString())).DragItems.Count == 0) { _isStartDrag = false; _isMouseDown = false; _selectedRow = -1; return; } DragItemData data = (DragItemData)drgevent.Data.GetData(typeof(DragItemData).ToString()); Point point = _table.PointToClient(new Point(drgevent.X, drgevent.Y)); int nRow = _table.TableModel.RowIndexAt(point.Y); if (nRow > 0) { nRow--; } Row hoverItem = _table.TableModel.Rows[nRow]; if (data.table != null) { if (data.table.SelectedIndicies.GetLength(0) > 0) { data.table.TableModel.Rows.Remove(data.table.SelectedItems[0]); _isMouseDown = false; _isStartDrag = false; _selectedRow = -1; _previousRow = null; } } if (hoverItem == null) { for (int i = 0; i < data.DragItems.Count; i++) { Row newItem = (Row)data.DragItems[i]; _table.TableModel.Rows.Add(newItem); } } else { for (int i = data.DragItems.Count - 1; i >= 0; i--) { Row newItem = (Row)data.DragItems[i]; if (nRow < 0) { _table.TableModel.Rows.Add(newItem); } else { _table.TableModel.Rows.Insert(nRow, newItem); } } } if (_previousRow != null) { _previousRow = null; } _table.Invalidate(); _isStartDrag = false; _isMouseDown = false; _selectedRow = -1; }
private DragItemData GetDataForDragDrop() { // create a drag item data object that will be used to pass along with the drag and drop DragItemData data = new DragItemData(this); // go through each of the selected items and // add them to the drag items collection // by creating a clone of the list item foreach (ListViewItem item in this.SelectedItems) { object copied_item = item.Clone(); (copied_item as ListViewItem).Name = "copy_of_" + item.Name; //System.Diagnostics.Debug.Print("\n*********************************************\nName-"+(copied_item as ListViewItem).Name+"-End Name\n*********************************************\n"); data.DragItems.Add(copied_item); } return data; }