C # ListView DragDrop event method Executing twice at a time

The method is executed twice in a row, and there is no obvious reason for this. This happens in VS2010 Express (4.0) and in VS2008 (3.5).

public GUI() { InitializeComponent(); this.lvwFiles.DragDrop += new System.Windows.Forms.DragEventHandler(this.lvwFiles_DragDrop); this.lvwFiles.DragEnter += new System.Windows.Forms.DragEventHandler(this.lvwFiles_DragEnter); } private void lvwFilesAdd(string path, string[] paths) { ... } private void lvwFilesWrite() { ... } private void lvwFiles_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } private void lvwFiles_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var paths = (string[])e.Data.GetData(DataFormats.FileDrop); var path = Path.GetDirectoryName(paths[0]); lvwFilesAdd(path, paths); lvwFilesWrite(); } } 
+6
c # events listview drag-and-drop
source share
1 answer

I followed the example of Microsoft and did not notice that the declarations in GUI.Designer.cs (automatically, using the IDE) and in GUI.cs (manually, from the example) are redundant.

 === GUI.cs === public GUI() { InitializeComponent(); this.lvwFiles.DragDrop += new System.Windows.Forms.DragEventHandler(this.lvwFiles_DragDrop); this.lvwFiles.DragEnter += new System.Windows.Forms.DragEventHandler(this.lvwFiles_DragEnter); } === GUI.Designer.cs === // // lvwFiles // ... this.lvwFiles.DragDrop += new System.Windows.Forms.DragEventHandler(this.lvwFiles_DragDrop); this.lvwFiles.DragEnter += new System.Windows.Forms.DragEventHandler(this.lvwFiles_DragEnter); 
+4
source share

All Articles