/// <summary> /// Raises the <see cref="Control.DragOver"/> event of the list view. /// </summary> /// <remarks> /// This determines the current insertion point of the items being moved. This also /// causes the insertion line to be drawn. /// </remarks> /// <param name="drgevent">A <see cref="DragEventArgs"/> describing the event arguments.</param> protected override void OnDragOver(DragEventArgs drgevent) { base.OnDragOver(drgevent); if (drgevent.Data.GetDataPresent(typeof(List <ListViewItem>))) { Point point = PointToClient(new Point(drgevent.X, drgevent.Y)); ListViewItem lviIndex = GetItemAt(point.X, point.Y); Int32 intNewIndex = Items.Count - 1; if (lviIndex != null) { lviIndex.EnsureVisible(); intNewIndex = lviIndex.Index; } if (intNewIndex != m_intInsertIndex) { m_intInsertIndex = intNewIndex; Invalidate(); } drgevent.Effect = DragDropEffects.Move; List <ListViewItem> data = (List <ListViewItem>)drgevent.Data.GetData(typeof(List <ListViewItem>)); ReorderingItemsEventArgs riaEventArgs = new ReorderingItemsEventArgs(); for (Int32 i = data.Count - 1; i >= 0; i--) { riaEventArgs.ReorderedListViewItems.Insert(0, new ReorderedItemsEventArgs.ReorderedListViewItem(data[i], data[i].Index, m_intInsertIndex + i)); } OnItemsReordering(riaEventArgs); if (riaEventArgs.Cancel) { drgevent.Effect = DragDropEffects.None; } } }
/// <summary> /// Raises the <see cref="ItemsReordering"/> event. /// </summary> /// <param name="e">An <see cref="EventArgs"/> describing the event arguments.</param> protected virtual void OnItemsReordering(ReorderingItemsEventArgs e) { ItemsReordering(this, e); }
/// <summary> /// Raises the <see cref="Control.DragOver"/> event of the list view. /// </summary> /// <remarks> /// This determines the current insertion point of the items being moved. This also /// causes the insertion line to be drawn. /// </remarks> /// <param name="drgevent">A <see cref="DragEventArgs"/> describing the event arguments.</param> protected override void OnDragOver(DragEventArgs drgevent) { base.OnDragOver(drgevent); if (drgevent.Data.GetDataPresent(typeof(List<ListViewItem>))) { Point point = PointToClient(new Point(drgevent.X, drgevent.Y)); ListViewItem lviIndex = GetItemAt(point.X, point.Y); Int32 intNewIndex = Items.Count - 1; if (lviIndex != null) { lviIndex.EnsureVisible(); intNewIndex = lviIndex.Index; } if (intNewIndex != m_intInsertIndex) { m_intInsertIndex = intNewIndex; Invalidate(); } drgevent.Effect = DragDropEffects.Move; List<ListViewItem> data = (List<ListViewItem>)drgevent.Data.GetData(typeof(List<ListViewItem>)); ReorderingItemsEventArgs riaEventArgs = new ReorderingItemsEventArgs(); for (Int32 i = data.Count - 1; i >= 0; i--) riaEventArgs.ReorderedListViewItems.Insert(0, new ReorderedItemsEventArgs.ReorderedListViewItem(data[i], data[i].Index, m_intInsertIndex + i)); OnItemsReordering(riaEventArgs); if (riaEventArgs.Cancel) drgevent.Effect = DragDropEffects.None; } }
/// <summary> /// Handles the <see cref="ReorderableListView.ItemsReordering"/> event of the plugin list. /// </summary> /// <remarks> /// This makes sure the new order is going to be valid. If not, the reordering event is stopped. /// </remarks> /// <param name="sender">The object that raised the event.</param> /// <param name="e">A <see cref="ReorderingItemsEventArgs"/> describing the event arguments.</param> private void rlvPlugins_ItemsReordering(object sender, ReorderingItemsEventArgs e) { List<Plugin> lstNewOrder = new List<Plugin>(ViewModel.ManagedPlugins); foreach (ReorderedItemsEventArgs.ReorderedListViewItem lviPlugin in e.ReorderedListViewItems) { Plugin plgMoved = (Plugin)lviPlugin.Item.Tag; lstNewOrder.RemoveAt(lviPlugin.OldIndex); lstNewOrder.Insert(lviPlugin.NewIndex, plgMoved); } e.Cancel = !ViewModel.ValidatePluginOrder(lstNewOrder); }