Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/16/11 15:00:24 (12 years ago)
Author:
mkommend
Message:

#1713: Implemented drag & drop operations for the checked state.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/CheckedItemListView.cs

    r6233 r7195  
    2020#endregion
    2121
     22using System.Linq;
    2223using System.Drawing;
    2324using System.Windows.Forms;
     
    5455    private Color backupColor = Color.Empty;
    5556    protected override void SetEnabledStateOfControls() {
    56       if(backupColor == Color.Empty) backupColor = base.itemsListView.BackColor;
     57      if (backupColor == Color.Empty) backupColor = base.itemsListView.BackColor;
    5758      base.SetEnabledStateOfControls();
    5859      if (ReadOnly || Locked)
     
    8889        doubleClick = true;
    8990    }
     91
     92    protected override void itemsListView_DragEnter(object sender, DragEventArgs e) {
     93      validDragOperation = false;
     94      if (Locked || ReadOnly) return;
     95
     96      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as ICheckedItemList<T>;
     97      if (data != null)
     98        validDragOperation = Content.Select(x => x.ToString()).SequenceEqual(data.Select(x => x.ToString()));
     99      else
     100        base.itemsListView_DragEnter(sender, e);
     101    }
     102
     103    protected override void itemsListView_DragOver(object sender, DragEventArgs e) {
     104      e.Effect = DragDropEffects.None;
     105      if (!validDragOperation) return;
     106
     107      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as ICheckedItemList<T>;
     108      if (data != null)
     109        e.Effect = DragDropEffects.Copy;
     110      else
     111        base.itemsListView_DragOver(sender, e);
     112    }
     113
     114    protected override void itemsListView_DragDrop(object sender, DragEventArgs e) {
     115      if (e.Effect == DragDropEffects.None) return;
     116      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat) as ICheckedItemList<T>;
     117      if (data != null) {
     118        for (int i = 0; i < Content.Count; i++) {
     119          Content.SetItemCheckedState(Content[i], data.ItemChecked(data[i]));
     120        }
     121      } else
     122        base.itemsListView_DragDrop(sender, e);
     123    }
    90124    #endregion
    91125
Note: See TracChangeset for help on using the changeset viewer.