• <i id='rPa36'><tr id='rPa36'><dt id='rPa36'><q id='rPa36'><span id='rPa36'><b id='rPa36'><form id='rPa36'><ins id='rPa36'></ins><ul id='rPa36'></ul><sub id='rPa36'></sub></form><legend id='rPa36'></legend><bdo id='rPa36'><pre id='rPa36'><center id='rPa36'></center></pre></bdo></b><th id='rPa36'></th></span></q></dt></tr></i><div id='rPa36'><tfoot id='rPa36'></tfoot><dl id='rPa36'><fieldset id='rPa36'></fieldset></dl></div>

    <tfoot id='rPa36'></tfoot>

  • <small id='rPa36'></small><noframes id='rPa36'>

  • <legend id='rPa36'><style id='rPa36'><dir id='rPa36'><q id='rPa36'></q></dir></style></legend>

      <bdo id='rPa36'></bdo><ul id='rPa36'></ul>

        如何拖动&amp;将项目放在同一个 ListView 中?

        时间:2023-08-25

                <tbody id='VLzQi'></tbody>
            1. <small id='VLzQi'></small><noframes id='VLzQi'>

              • <bdo id='VLzQi'></bdo><ul id='VLzQi'></ul>
                • <i id='VLzQi'><tr id='VLzQi'><dt id='VLzQi'><q id='VLzQi'><span id='VLzQi'><b id='VLzQi'><form id='VLzQi'><ins id='VLzQi'></ins><ul id='VLzQi'></ul><sub id='VLzQi'></sub></form><legend id='VLzQi'></legend><bdo id='VLzQi'><pre id='VLzQi'><center id='VLzQi'></center></pre></bdo></b><th id='VLzQi'></th></span></q></dt></tr></i><div id='VLzQi'><tfoot id='VLzQi'></tfoot><dl id='VLzQi'><fieldset id='VLzQi'></fieldset></dl></div>

                • <tfoot id='VLzQi'></tfoot>
                  <legend id='VLzQi'><style id='VLzQi'><dir id='VLzQi'><q id='VLzQi'></q></dir></style></legend>

                • 本文介绍了如何拖动&amp;将项目放在同一个 ListView 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  考虑到这是一个显示文件和文件夹的 ListView,我已经为复制/移动/重命名/显示属性等编写了代码,我只需要最后一件事.如何像在 Windows 资源管理器中一样拖放到同一个 ListView 中,我有移动和复制功能,我只需要获取用户在某个文件夹中放置的项目或以其他方式我需要获取这两个参数来调用 复制功能

                  Consider this is a ListView that shows files and folders, I have already wrote code for copy/move/rename/show properties ...etc and I just need one more last thing. how to drag and drop in the same ListView like in Windows Explorer, I have move and copy functions, and I just need to get the items which user drops in some folder or in other way I need to get these two parameters to call copy function

                  void copy(ListViewItem [] droppedItems, string destination path)
                  {
                   // Copy target to destination
                  }
                  

                  推荐答案

                  首先将列表视图的 AllowDrop 属性设置为 true.实现 ItemDrag 事件以检测拖动的开始.我将使用一个私有变量来确保 D+D 仅在控件内部起作用:

                  Start by setting the list view's AllowDrop property to true. Implementing the ItemDrag event to detect the start of a drag. I'll use a private variable to ensure that D+D only works inside of the control:

                      bool privateDrag;
                  
                      private void listView1_ItemDrag(object sender, ItemDragEventArgs e) {
                          privateDrag = true;
                          DoDragDrop(e.Item, DragDropEffects.Copy);
                          privateDrag = false;
                      }
                  

                  接下来你需要 DragEnter 事件,它会立即触发:

                  Next you'll need the DragEnter event, it will fire immediately:

                      private void listView1_DragEnter(object sender, DragEventArgs e) {
                          if (privateDrag) e.Effect = e.AllowedEffect;
                      }
                  

                  接下来,您需要有选择地选择用户可以放置的项目.这需要 DragOver 事件并检查悬停的项目.您需要将代表文件夹的项目与常规的文件"项目区分开来.一种方法是使用 ListViewItem.Tag 属性.例如,您可以将其设置为文件夹的路径.使这段代码工作:

                  Next you'll want to be selective about what item the user can drop on. That requires the DragOver event and checking which item is being hovered. You'll need to distinguish items that represent a folder from regular 'file' items. One way you can do so is by using the ListViewItem.Tag property. You could for example set it to the path of the folder. Making this code work:

                      private void listView1_DragOver(object sender, DragEventArgs e) {
                          var pos = listView1.PointToClient(new Point(e.X, e.Y));
                          var hit = listView1.HitTest(pos);
                          if (hit.Item != null && hit.Item.Tag != null) {
                              var dragItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
                              copy(dragItem, (string)hit.Item.Tag);
                          }
                      }
                  

                  如果您想支持拖动多个项目,请将您的拖动对象设置为 ListView.SelectedIndices 属性.

                  If you want to support dragging multiple items then make your drag object the ListView.SelectedIndices property.

                  这篇关于如何拖动&amp;将项目放在同一个 ListView 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Windows 资源管理器上获取拖放文件的文件路径 下一篇:Windows Phone 8.1 中 UIElement 的拖放延迟

                  相关文章

                  最新文章

                  <legend id='U72nj'><style id='U72nj'><dir id='U72nj'><q id='U72nj'></q></dir></style></legend>
                • <i id='U72nj'><tr id='U72nj'><dt id='U72nj'><q id='U72nj'><span id='U72nj'><b id='U72nj'><form id='U72nj'><ins id='U72nj'></ins><ul id='U72nj'></ul><sub id='U72nj'></sub></form><legend id='U72nj'></legend><bdo id='U72nj'><pre id='U72nj'><center id='U72nj'></center></pre></bdo></b><th id='U72nj'></th></span></q></dt></tr></i><div id='U72nj'><tfoot id='U72nj'></tfoot><dl id='U72nj'><fieldset id='U72nj'></fieldset></dl></div>

                  <tfoot id='U72nj'></tfoot>

                    <small id='U72nj'></small><noframes id='U72nj'>

                      • <bdo id='U72nj'></bdo><ul id='U72nj'></ul>